帮助中心帮助中心
htmlTree
解析HTML树
自从R2018b
一个htmlTree对象表示一个解析HTML元素或节点。提取感兴趣的部分findElement函数或孩子们财产,提取文本使用extractHTMLText函数。
findElement
孩子们
extractHTMLText
树= htmlTree(代码)
例子
树= htmlTree (代码)解析HTML代码的字符串代码并返回结果树结构。
树= htmlTree (代码)
树
代码
提示
解析XML代码,使用readstruct函数。
readstruct
全部展开
HTML代码,指定为字符串数组,特征向量,或单元阵列的特征向量。
阅读从一个web页面的HTML代码,使用webread。
webread
从一个HTML文件中提取文本,使用extractFileText。
extractFileText
例子:“< a href = " //www.tatmou.com " > MathWorks < / >”
“< a href = " //www.tatmou.com " > MathWorks < / >”
数据类型:字符|字符串|细胞
字符
字符串
细胞
元素的直系后代,指定为一个htmlTree数组中。
父
树中的父节点,指定为一个htmlTree对象。
如果HTML树是一个根节点,那么的价值父是失踪。
失踪
的名字
HTML元素名称,指定为字符串标量。
有关更多信息,请参见HTML元素。
getAttribute
ismissing
全部折叠
从URL读取HTML代码//www.tatmou.com/help/textanalytics使用webread。
//www.tatmou.com/help/textanalytics
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函数。
发现所有的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
选择器=“一个”;子树= 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”。
“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 "
解析HTML代码使用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...↵" "© 1994-2021 The MathWorks, Inc." "↵ Join the conversation↵"
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...↵
© 1994-2021 The MathWorks, Inc.
↵ Join the conversation↵
一个典型的HTML元素包含以下组件:
元素名称- HTML标签的名称。元素名称对应的名字属性的HTML树。
属性——关于标签的附加信息。HTML属性表单的名字= "价值”,在那里的名字和价值分别表示该属性名称和值。出现在开幕式HTML标签的属性。属性值从一个HTML树,使用getAttribute。
的名字= "价值”
价值
内容——元素内容。打开和关闭HTML标记之间的内容出现。内容可以是文本数据或嵌套的HTML元素。从一个提取文本htmlTree对象,使用extractHTMLText。嵌套的HTML元素htmlTree对象,使用孩子们财产。
例如,HTML元素< a href = " //www.tatmou.com " > < / >回家包括以下组件:
< a href = " //www.tatmou.com " > < / >回家
一个
href
“//www.tatmou.com”
家
当创建一个htmlTree对象,软件自动重组畸形的有效结构输入HTML代码。这个重组过程包括添加、删除和编辑元素以及重新排列树结构。从R2021a,软件使用一个更新算法重组畸形的HTML。这种变化可以导致htmlTree在R2021a中创建的对象或晚有不同的大小,结构和内容与以前版本相比。
从R2021a,当加载htmlTree对象从垫文件中创建一个R2020b或之前,软件自动进行重组htmlTree用来创建对象使用相同的算法htmlTree对象。当加载htmlTree对象从垫文件中创建R2021a或后,软件不进行重组htmlTree对象。
这张桌子突出了一些引人注目的重组过程的步骤:
从R2021a,当创建一个htmlTree对象从HTML代码,软件自动插入失踪<头>,<标题>和其他元素。在以前的版本中,htmlTree对象只包括这些元素存在时,在输入代码。
<头>
<标题>
当加载htmlTree对象从垫子上创建的文件在早期版本中,软件会自动插入<头>和<标题>元素。当加载htmlTree对象从垫文件中创建R2021a或之后,该软件不会自动插入这些元素。
从R2021a,当创建一个htmlTree对象从HTML代码,软件时自动插入缺失的元素父元素和子元素是不一致的。例如,当一个<李>(列表项)元素没有父母< ul >(无序列表)或< ol >(无序列表)元素,软件会自动添加一个< ul >使HTML元素有效。这可以导致不同的输出与早期的版本相比。
<李>
< ul >
< ol >
当加载htmlTree对象从垫子上创建的文件在早期版本中,软件会自动插入缺失的元素。当加载htmlTree对象从垫文件中创建R2021a或之后,该软件不会自动插入缺失的元素。
当创建一个htmlTree对象与畸形的HTML代码,软件可能丢弃的部分文本。例如,如果输入代码字符串“< div > < /”,那么软件丢弃的文本“< /”。
“< div > < /”
“< /”
extractHTMLText|readPDFFormData|findElement|getAttribute|ismissing|tokenizedDocument
readPDFFormData
tokenizedDocument
这种版本modificada德埃斯特比如。害怕Desea abrir埃斯特比如con sus modificaciones吗?
Ha事实clic en联合国围绕此时一个埃斯特第一de MATLAB:
Ejecute el第一introduciendolo en la ventana de第一de MATLAB。洛杉矶navegadores网络没有admiten第一de MATLAB。
选择一个网站
选择一个网站翻译内容,看到当地事件和提供。根据你的位置,我们建议您选择:。
你也可以从下面的列表中选择一个网站:
选择中国网站(中文或英文)最佳站点的性能。其他MathWorks国家网站不优化的访问你的位置。
联系你当地的办公室