Python - Xpath Helper(xpath辅助插件)

本文章已经生成可运行项目,

XPath Helper是一款免费的Chrome插件,专用于网页解析和爬虫辅助。它允许用户轻松获取网页数据的XPath,以便进行批量爬取。下载插件后,通过拖拽安装到Chrome浏览器,然后在网页上右键检查,复制XPath并输入到XPath Helper查询框,即可高亮显示对应元素。此外,插件还支持批量获取数据、链接和文本等功能,对于前端开发者和爬虫工程师来说非常实用。

如下图所示,在QUERY输入框中写XPath代码,右侧文本框会显示查找到的xpath结果,在网页中也会高亮度显示xpath所在的位置。

一、下载XPath Helper

XPath Helper下载:XPath Helper_2.0.2_Chrome插件下载_极简插件

1、进入并点击 ‘推荐下载’ 即可下载出压缩包,打开文件下载位置为一个zip文

2、将压缩包解压, 有两个文件

二、加载XPath Helper插件至谷歌浏览器

1、使用谷歌浏览器,打开设置(Settings)


2、点击扩展程序(Extensions)

3、打开 开发者模式(Developer mode)


4、将名为 ’hgimnogjllphhhkhlmebbmlgjoejdpjl_2.0.2_chrome.zzzmh.cn.crx‘ 的文件拖拽复制到chrome浏览器

5、点击弹窗中 ‘Add extension’ (添加扩展) 按钮;到此已将 Xpath Helper 插件已添加至谷歌浏览器

6、将 Xpath Helper 钉( pin ) 在主页上, 便于后期插件的使用

三、Xpath Helper使用

这里以 www.baidu.com 页面热搜为例

1、右键热搜链接,点击检查(inspect)

2、在弹出的 开发者工具栏 复制 Xpath (Copy Xpath) , 并点击上方 xpath helper 插件 

3、点击插件后, 将刚复制的 xpath 粘贴至查询框

​ xpath正确,则结果框中显示网页中相应元素,且网页中相应数据高亮显示

//*[@id="hotsearch-content-wrapper"]/li[2]/a/span[2]

//*[@id="hotsearch-content-wrapper"]/li[2]/a/span[2]/text()

4、批量获取数据

//*[@id="hotsearch-content-wrapper"]/li/a/span[2]

5、获取链接

//*[@id="hotsearch-content-wrapper"]/li/a/@href

6、获取文本

//*[@id="hotsearch-content-wrapper"]/li/a/span[2]/text()

本文章已经生成可运行项目
提取,编辑和轻松评估XPath查询。 XPath的助手很容易提取,编辑,并在任何网页评估XPath查询。 重要提示:安装此扩展后,必须重新加载任何现有的选项卡或重新启动Chrome浏览器扩展工作。 说明: 1.打开一个新的标签,并导航到任何网页。 2.按Ctrl-Shift键-X(或OS X命令移-X),或单击工具栏上的XPath的助手按钮,以打开XPath助手控制台。 3.按住Shift键将鼠标悬停在页面上的元素。查询框将不断更新,以显示鼠标指针下方的元件XPath查询,结果框将显示当前查询的结果。 4.如果需要,请在控制台直接编辑XPath查询。结果框会立即反映更改。 5.重复步骤(2)关闭控制台。 如果控制台在你的方式获得,按住Shift键,然后将鼠标移动到它; 它会移动到页面的相对侧。 一个忠告:当渲染HTML表格,浏览器插入人工<TBODY>标记到DOM,这将在随后通过该扩展提取查询显示出来。 Extract, edit, and evaluate XPath queries with ease. XPath Helper makes it easy to extract, edit, and evaluate XPath queries on any webpage. IMPORTANT: After installing this extension, you must reload any existing tabs or restart Chrome for the extension to work. Instructions: 1. Open a new tab and navigate to any webpage. 2. Hit Ctrl-Shift-X (or Command-Shift-X on OS X), or click the XPath Helper button in the toolbar, 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 XPath query for the element below the mouse pointer, and the results box will show the results for the current query. 4. If desired, edit the XPath query directly in the console. The results box will immediately reflect your changes. 5. Repeat step (2) to close the console. If the console gets in your way, hold down Shift and then move your mouse over it; it will move to the opposite side of the page. One word of caution: When rendering HTML tables, Chrome inserts artificial <tbody> tags into the DOM, which will consequently show up in queries extracted by this extension.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值