使用chrome调试xpath

相信玩过爬虫的都知道一些库,如lxml(python),可以使用xpath方便地对HTML进行提取,但当真正用的时候,问题就来了,想找到一个元素往往要调试好几遍,而且得先code,下面提供了几个工具及如何用chrome进行xpath test

1.XPath Helper

https://chrome.google.com/webstore/detail/xpath-helper/hgimnogjllphhhkhlmebbmlgjoejdpjl

1. Open a new tab and navigate to your favorite webpage.
2. Hit Ctrl-Shift-X to open the XPath Helper console.
3. Hold down Shift as you mouse over elements on the page. The query box will continuously update to show the full XPath query for the element below the mouse pointer. The results box to its right will show the evaluated results for the query.
4. If desired, edit the XPath query directly in the console. The results box will immediately reflect any changes.
5. Hit Ctrl-Shift-X again to close the console.

2.Xpath Finder – xpath查找助手

https://chrome.google.com/webstore/detail/xpath-finder/ijaobnmmgonppmablhldddpfmgpklbfh/related

在chrome开发者工具里增加一个面板,帮助你快速查找匹配XPATH表达式的元素。

1. 匹配的节点会用红色边框突出显示。
2. 在结果列表里可以直接inspect对应节点。
3. 记录XPATH查找历史,方便查看历史。

3.chrome console

F12->$x(“//title”)

[<title>Online Tools for Software Developers (Free)</title>]

发表评论

电子邮件地址不会被公开。 必填项已用*标注