主要内容

htmlTree

解析的HTML树

描述

一个htmlTreeobject表示已解析的HTML元素或节点。方法提取感兴趣的部分findElement函数或孩子们属性提取文本extractHTMLText函数。

创建

描述

例子

= htmlTree (代码解析字符串中的HTML代码代码并返回生成的树结构。

提示

要解析XML代码,请使用readstruct函数。

输入参数

全部展开

HTML代码,指定为字符串数组、字符向量或字符向量的单元格数组。

提示

  • 要从网页中读取HTML代码,请使用webread

  • 要从HTML文件中提取文本,请使用extractFileText

例子:“< a href = " //www.tatmou.com " > MathWorks < / >”

数据类型:字符|字符串|细胞

属性

全部展开

元素的直接后代,指定为htmlTree数组中。

树中的父节点,指定为htmlTree对象。

如果HTML树是根节点,则失踪

HTML元素名称,指定为字符串标量。

有关更多信息,请参见HTML元素

对象的功能

findElement 在HTML树中查找元素
getAttribute 读取HTML树根节点的HTML属性
extractHTMLText 从HTML中提取文本
ismissing 查找没有值的HTML树

例子

全部折叠

从URL读取HTML代码//www.tatmou.com/help/textanalytics使用webread

url =“//www.tatmou.com/help/textanalytics”;代码= webread(url);

使用解析HTML代码htmlTree

tree = htmlTree(code);

查看树的根节点的元素名称。

树。的名字
ans = "HTML"

查看根节点的子节点。

树。孩子们
ans = 4×1 htmlTree: " " 文本分析工具箱文档




从HTML树中提取文本extractHTMLText

str = extractHTMLText(树)
文本分析工具箱™为预处理、分析和建模文本数据提供了算法和可视化。使用工具箱创建的模型可用于情感分析、预测性维护和主题建模等应用程序。文本分析工具箱包括用于处理来自设备日志、新闻提要、调查、操作员报告和社交媒体等来源的原始文本的工具。您可以从流行的文件格式提取文本、预处理原始文本、提取单个单词、将文本转换为数字表示以及构建统计模型。使用诸如LSA、LDA和词嵌入等机器学习技术,您可以从高维文本数据集中找到集群并创建特征。使用文本分析工具箱创建的功能可以与来自其他数据源的功能相结合,以构建利用文本、数字和其他类型数据的机器学习模型。”

从URL读取HTML代码//www.tatmou.com/help/textanalytics使用webread函数。

url =“//www.tatmou.com/help/textanalytics”;代码= webread(url);

使用解析HTML代码htmlTree

tree = htmlTree(code);

查找HTML树中的所有超链接findElement.超链接是具有元素名称的节点“一个”

选择器=“一个”;subtrees = findElement(树,选择器);

查看前几个子树。

子树(1:10)
ans = 10×1 htmlTree:<类= " skip_link sr-only " href = " # content_container " >跳到内容< / > < A href = " //www.tatmou.com?s_tid=gn_logo " class = " svg_link navbar-brand”> < IMG src = " /图片/响应/全球/ pic-header-mathworks-logo.svg”类=“mw_logo”alt = " MathWorks " / > < / > < A href = " //www.tatmou.com/pro下载188bet金宝搏ducts.html?s_tid=gn_ps " >产品< / > < A href = " //www.tatmou.com/so金宝搏官方网站lutions.html?s_tid=gn_sol " >解决方案< / > < A href = " //www.tatmou.com/academia.html?s_tid=gn_acad " >学术界< / > <支持href = " https://www.mathworks金宝app.com/support.html?s_tid=gn_supp " > < / > < A href = " //www.tatmou.com/matlabcentral/?s_tid=gn_mlc " >社区< / > < A href = " //www.tatmou.com/company/events.html?s_tid=gn_ev " >事件< / > < A href = " https://www.mathw下载188bet金宝搏orks.com/products/get-matlab.html?s_tid=gn_getml " >得到MATLAB < / > < A href = " //www.tatmou.com?s_tid=gn_logo " class = " svg_link pull-left”> < IMG src = " /图片/响应/全球/ pic-header-mathworks-logo.svg”类=“mw_logo”alt = " MathWorks " / > < / >

从子树中提取文本extractHTMLText.结果包含页面上每个链接的链接文本。

str = extractHTMLText(subtrees);str (1:10)
ans =10×1的字符串“跳到内容" "" "产品”“解决方案”“学下载188bet金宝搏术界”“支持”“社区”金宝搏官方网站“事件”“获取MATLAB”“”金宝app

从URL读取HTML代码//www.tatmou.com/help/textanalytics使用webread

url =“//www.tatmou.com/help/textanalytics”;代码= webread(url);

使用解析HTML代码htmlTree

tree = htmlTree(code);

查找HTML树中的所有超链接findElement.超链接是具有元素名称的节点“一个”

选择器=“一个”;subtrees = findElement(树,选择器);子树(1:10)
ans = 10×1 htmlTree:< class = " svg_link navbar-brand " href = " //www.tatmou.com?s_tid=gn_logo " > < IMG alt = " MathWorks " class = " mw_logo " src = " /图片/响应全球/ pic-header-mathworks-logo.svg " / > < / > < class = " mwa-nav_login " href = " //www.tatmou.com/login?uri=http: / / www.tatmou.com/help/textanalytics/index.html " >在< / > < A href = " https:下载188bet金宝搏//www.tatmou.com/products.html?s_tid=gn_ps " >产品< / > < A href = " https金宝搏官方网站://www.tatmou.com/solutions.html?s_tid=gn_sol " > < / > <一个解决方案学术界href = " //www.tatmou.com/academia.html?s_tid=gn_acad " > < / > < A href = " https://www.mathwork金宝apps.com/support.html?s_tid=gn_supp " > < / >支持社区< A href = " //www.tatmou.com/matlabcentral/?s_tid=gn_mlc " > < / > < A href = " //www.tatmou.com/company/events.html?s_tid=gn_ev " >事件< / > < A href = " //www.tatmou.com/company/aboutus/contact_us.html?s_tid=gn_cntus " >联系我们< / > < A href = " //www.tatmou.com/store?s_cid=store_top_nav& s_tid = gn_store " >如何购买< / >

使用获取超链接引用getAttribute.指定属性名“href”

attr =“href”;str = getAttribute(subtrees,attr);str (1:10)
ans =10×1字符串数组//www.tatmou.com?s_tid=gn_logo“//www.tatmou.com/login?uri=//www.tatmou.com/help/textanalytics/index.html”“//www.tatmou.com/prod下载188bet金宝搏ucts.html?s_tid=gn_ps”“//www.tatmou.com/solut金宝搏官方网站ions.html?s_tid=gn_sol”“//www.tatmou.com/academia.html?s_tid=gn_acad”“https://www.mat金宝apphworks.com/support.html?s_tid=gn_supp”“//www.tatmou.com/matlabcentral/?s_tid=gn_mlc”“//www.tatmou.com/company/events.html?s_tid=gn_ev”“//www.tatmou.com/company/aboutus/contact_us.html?s_tid=gn_cntus”“//www.tatmou.com/store?s_cid=store_top_nav&s_tid=gn_store”

从URL读取HTML代码//www.tatmou.com/help/textanalytics使用webread函数。

url =“//www.tatmou.com/help/textanalytics”;代码= webread(url);

方法解析HTML代码htmlTree函数。

tree = htmlTree(code);

控件查找HTML树中的所有段落findElement函数。段落是元素名为“P”的节点。

subtrees = findElement(树,“P”);

方法将子树转换为字符串字符串函数。

STR = string(subtrees)
str =26日×1的字符串"

(文档 (帮助中心 (

) " "

文本分析工具箱™提供预处理、分析和建模文本数据的算法和可视化。使用工具箱创建的模型可用于情感分析、预测性维护和主题建模等应用程序。

" "

文本分析工具箱包括用于处理来自设备日志、新闻提要、调查、操作员报告和社交媒体等来源的原始文本的工具。您可以从流行的文件格式提取文本、预处理原始文本、提取单个单词、将文本转换为数字表示以及构建统计模型。

" "

使用机器学习技术,如LSA、LDA和词嵌入,您可以从高维文本数据集中找到集群并创建特征。使用“文本分析工具箱”创建的功能可以与来自其他数据源的功能相结合,以构建利用文本、数字和其他类型数据的机器学习模型。< / P > " < P类=“category_desc”>学习基本的文本分析工具箱< / P > " < P类=“category_desc”>文本数据导入MATLAB <一口>®> < /晚餐和预处理分析< / P > " < P类=“category_desc”>开发预测模型使用主题模型和词嵌入的< / P > " < P类=“category_desc”>可视化文本数据和模型使用云词和文本散点图< / P > " < P类=“category_desc”>语言支持的信息以文本分析工具箱< / P > " < P >你点击一个链接金宝app对应于此MATLAB命令:

" "

在MATLAB命令窗口中输入该命令运行。Web浏览器不支持MATLAB命令。金宝app

" "

选择一个网站获取可用的翻译内容,并查看当地的活动和优惠。根据您的位置,我们建议您选择:

" "

You can also select a web site from the following list:

" "

Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.

" "

Contact your local office

" "

Explore Products

" "

Try or Buy

" "

Learn to Use

" "

Get Support

" "

About MathWorks

" "

MathWorks

" "

Accelerating the pace of engineering and science

" "

MathWorks is the leading developer of mathematical computing software for engineers and scientists.

" "

Discover...

" "" "

Join the conversation

"

更多关于

全部展开

兼容性的考虑

全部展开

R2021a的行为发生了变化

在R2018b中引入