htmlTree

解析HTML树

描述

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

创建

描述

例子

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

输入参数

全部展开

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

树= htmlTree(代码);

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

树。名称
ans =“HTML”

查看根节点的子节点。

树。孩子们
ans = 4×1 htmlTree:Text Analytics Toolbox Documentation




 < 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 " class = " mw_logo " src = " /图片/响应全球/ pic-header-mathworks-logo.svg " / > < / > < / DIV > < / DIV > < / DIV > < DIV class = "行visible-xs visible-sm”> < DIV

从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 " class = " mw_logo " src = " /图片/响应全球/ pic-header-mathworks-logo.svg " / > < / > < A href = " https://www.下载188bet金宝搏mathworks.com/products.html?s_tid=gn_ps " >产品< / > < A href = " https://www金宝搏官方网站.mathworks.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 " > < / > <一个事件href = " //www.tatmou.com/company/aboutus/contact_us.html?s_tid=gn_cntus " >联系我们< / > < A href = " https://www.mathworks.下载188bet金宝搏com/products/get-matlab.html?s_tid=gn_getml " >得到MATLAB < / > < class = " svg_link pull-left " href = " //www.tatmou.com?s_tid=gn_logo " > < IMG alt =“MathWorks”class =“mw_logo”src = " /图片/响应/全球/ pic-header-mathworks-logo.svg " / > < / >

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

str = extractHTMLText(子树);str (1:10)
ans =10×1字符串""产品下载188bet金宝搏""解决方案""学术界金宝搏官方网站""支持"金宝app"社区""事件""联系我们""获取MATLAB" ""

从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 " 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 " >在< / > <迹象产品href = " https://www.mathworks下载188bet金宝搏.com/products.html?s_tid=gn_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 = "金宝app //www.tatmou.com/support.html?s_tid=gn_supp " > < / > <支持社区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=//www.tatmou.com/help/textanalytics/index.html" "//www.tatmou.com/下载188bet金宝搏products.html?s_tid=gn_ps" "//www.tatmou.com/金宝搏官方网站solutions.html?s_tid=gn_sol" "//www.tatmou.com/academia.html?s_tid=gn_acad"“//www.tatmou.com/金宝appsupport.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”

更多关于

全部展开

介绍了R2018b