很少說,直接上地址: 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標籤內文本內容測試