很少说,直接上地址: http://zvon.org/xxl/XPathTutorial/General/examples.htmlhtml
点击左上角“中文”便可显示中文翻译实例。linux
xpath用于解析html,xml.xhtml这一类标签文档很方便,也很直接,用简短的语法提取标签文档的内容、属性等。bash
在linux下终端能够用xpath
, xmllint --xpath
这一类的工具来即时测试xpath语法提取效果。curl
一个简易的范例,从cnBeta获取首页热门新闻的标题和摘要工具
curl -s http://www.cnbeta.com | xmllint --html --xpath '/html/body/div/section/section/section/div/div/div[@id="hot"]/dl/dt/a' - 2>/dev/null <a href="/articles/321967.htm" target="_blank">LG将推出圆形智能手表与摩托360竞争</a><a href="/articles/321965.htm" target="_blank">小米回应电量虚标问题 称质检总局抽样系非官方渠道购买</a><a href="/articles/321985.htm" target="_blank">充电宝冒烟 北京地铁15号线一列车清车</a>
最后xpath改成a/text()
便可获取a标签内文本内容测试