主要内容

htmlTree

解析HTML树

自从R2018b

描述

一个htmlTree对象表示一个解析HTML元素或节点。提取感兴趣的部分findElement函数或孩子们财产,提取文本使用extractHTMLText函数。

创建

描述

例子

= htmlTree (代码)解析HTML代码的字符串代码并返回结果树结构。

提示

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

输入参数

全部展开

HTML代码,指定为字符串数组,特征向量,或单元阵列的特征向量。

提示

  • 阅读从一个web页面的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

树= htmlTree(代码);

视图树的根节点的元素名称。

tree.Name
ans =“HTML”

查看根节点的孩子节点。

tree.Children
ans = 4×1 htmlTree: " <头> <标题>文本分析工具箱文档< /名称> < META charset = " utf - 8 " / > < META内容=“宽度=设备宽度,初始= 1.0 " name = "视窗" / > < META内容=“IE =边缘”http-equiv = " X-UA-Compatible " / > <链接的href = " / includes_content /响应/ css /引导/ bootstrap.min。css样式表" rel = " " type = " text / css " href = " / > <联系/ includes_content /响应/ css / site6.css吗?201903年“rel = "样式表" type = " text / css " href = " / > <联系/ includes_content /响应/ css / site6_lg.css吗?201903“媒体= "屏幕和(min-width: 1200 px) " / > < " rel = "样式表链接href = " / includes_content /响应/ css / site6_md.css吗?201903年“媒体= "屏幕和(min-width: 992 px)和(max-width: 1199 px) " / > < " rel = "样式表链接href = " / includes_content /响应/ css / site6_sm + xs.css吗?201903“媒体= "屏幕和(max-width: 991 px) " / > < " rel = "样式表链接href = " / includes_content /响应/ css / site6_sm.css吗?201903年“媒体= "屏幕和(min-width: 768 px)和(max-width: 991 px) " / > < " rel = "样式表链接href = " / includes_content /响应/ css / site6_…”“<身体id = " responsive_offcanvas " > < !——移动TopNav:开始- - > < DIV class = "头visible-xs visible-sm " id =“header_mobile”翻译= "不" > <导航类= =“导航”>“navbar navbar-default”作用< DIV class = " container-fluid " > < DIV class = "行" > < DIV class = " col-xs-12 " > < DIV class = " navbar-header " > <按钮类=“navbar-toggle topnav_toggle”数据目标= " # topnav_collapse " data-toggle =“崩溃”type = "按钮" > <跨类= " sr-only " >切换主要导航< / SPAN > < SPAN class = "图标菜单" / > < /按钮> < class = " svg_link navbar-brand " href = " //www.tatmou.com?s_tid = gn_logo " > < IMG alt = " MathWorks”类= " mw_logo " src = " /图片/响应/全球/ pic-header-mathworks-logo。svg " / > < / > < / DIV > < / DIV > < / DIV > < DIV class = "行visible-xs visible-sm”> < DIV class = " col-xs-12 " > < DIV class = " navbar-collapse崩溃" id = " topnav_collapse " > < UL类= " nav navbar-nav " id = " topnav " > <李类= " headernav_login " > < class = " mwa-nav_login " href = " //www.tatmou.com/login?uri=http: / /www.tatmou.com/help/textanalytics/index.html " >标志…

从HTML树中提取文本使用extractHTMLText

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

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

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

解析HTML代码使用htmlTree

树= htmlTree(代码);

发现所有的HTML树中的超链接使用findElement。超链接的节点元素名称“一个”

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

查看前几子树。

子树(1:10)
ans = 10×1 htmlTree: < class = " 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 = " https://www.math下载188bet金宝搏works.com/products.html?产品s_tid = gn_下载188bet金宝搏ps " > < / > < A href = " https://www.mathworks.金宝搏官方网站com/solutions.html?s_tid = gn_sol金宝搏官方网站 " >解决方案< / > < A href = " //www.tatmou.com/academia.html?学术界s_tid = gn_acad " > < / > < A href = " https://www.mathworks金宝app.com/support.html?s_tid支持= gn_sup金宝appp " > < / > < 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.mathwork下载188bet金宝搏s.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(子树);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

树= htmlTree(代码);

发现所有的HTML树中的超链接使用findElement。超链接的节点元素名称“一个”

选择器=“一个”;子树= findElement(树,选择器);子树(1:10)
ans = 10×1 htmlTree: < class = " svg_link navbar-brand " href = " //www.tatmou.com?s_tid = gn_logo " > < IMG alt = " MathWorks”类= " 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://www.下载188bet金宝搏mathworks.com/products.html?产品s_tid = gn_下载188bet金宝搏ps " > < / > < A href = " https://www.mathworks.金宝搏官方网站com/solutions.html?s_tid = gn_sol金宝搏官方网站 " >解决方案< / > < A href = " //www.tatmou.com/academia.html?学术界s_tid = gn_acad " > < / > < A href = " https://www.mathworks金宝app.com/support.html?s_tid支持= gn_sup金宝appp " > < / > < 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(子树,attr);str (1:10)
ans =10×1的字符串数组“//www.tatmou.com?s_tid = gn_logo”“//www.tatmou.com/login?uri=http: / /www.tatmou.com/help/textanalytics/index.html " https://www.mathworks.c下载188bet金宝搏om/products.html?s_tid = gn_ps " https://www.mathworks.co金宝搏官方网站m/solutions.html?s_tid = gn_sol " //www.tatmou.com/academia.html?s_tid = gn_acad " https://www.mathworks.co金宝appm/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函数。

树= htmlTree(代码);

找到所有的段落使用HTML树findElement函数。段落与元素名称“P”节点。

子树= findElement(树,“P”);

使用子树转换为字符串字符串函数。

str =字符串(子树)
str =26日×1的字符串h1“< P类= >↵< A href = " . . /索引。html coming_from_product“类= >文档< / >↵< A href = " . . /索引。html”类= " not_coming_from_product " > < / >帮助中心↵< / P > " " < P >文本分析工具箱™提供预处理的算法和可视化、分析、建模和文本数据。使用工具箱创建的模型可以用于应用,如情绪分析、预测性维护,和主题建模。< / P > " < P >文本分析工具箱包括工具处理原始文本来源设备日志等新闻,调查,运营商报告,和社交媒体。你可以从流行的文件格式中提取文本,原始文本进行预处理,提取单词,将文本转换成数值表示,并建立统计模型。< / P > " < P >使用机器学习技术,如LSA, LDA,字嵌入的,你可以找到集群和从高维文本数据集创建功能。特征与文本分析工具箱可以创建结合特性从其他数据源构建机器学习模型,利用文本,数字,和其他类型的数据。< / P > " < P class = " category_desc " >学习基本的文本分析工具箱< / P > " < P class = " category_desc " >文本数据导入MATLAB®<一口> < /一口>和预处理分析< / P > " < P class = " category_desc " >开发预测模型使用主题模型和词嵌入的< / P > " < P class = " category_desc " >可视化文本数据和模型使用云词和文本散点图< / P > " < P class = " category_desc " >语言支持的信息以文本分析工具箱< / P > " < P >你点击一个链接对应MATLAB命令:< / P > " < P >运行该命令通过输入MATLAB命令窗口。金宝appWeb浏览器不支持MATLAB命令。金宝app< / P > " < P >选择一个网站翻译内容,看到当地事件和提供。 Based on your location, we recommend that you select: .

" "

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

"

更多关于

全部展开

版本历史

介绍了R2018b

全部展开