前言
写过爬虫和网页解析的人都知道,在定位、获取xpath路径上要花费大量的时间,甚至有时候当爬虫框架成熟之后,基本上主要的时间都花费在了页面的解析上。
在没有这些辅助工具的日子里,我们只能通过搜索html源代码,定位一些id去找到对应的位置,非常的麻烦,而且经常出错。
这里分享一个chrome浏览器的小技巧
比如现在我们在抓取 博客园首页的文章xpath 路径
打开 开发者工具,鼠标选中标题元素上,右键》Capy 即可获取xpath。
执行capy xpath
,获取标题元素在当前父节点的xpath
//*[@id="post_list"]/div[1]/div[2]/h3/a
执行capy full xpath
,获取标题元素的在html文档中的完整xpath
/html/body/div[1]/div[4]/div[6]/div[1]/div[2]/h3/a
我觉得这样还不够方便,毕竟你复制了没法即时查看。所以我们需要这款开源的爬虫利器!
Xpath Helper
xpath helper插件是一款免费的chrome爬虫网页解析工具。
可以帮助用户解决在获取xpath路径时无法正常定位等问题。
该插件主要能帮助你在各类网站上通过按shift键选择想要查看的页面元素来提取查询其代码,同时你还能对查询出来的代码进行编