8

Python爬虫编程思想(45):在Chrome中自动获得XPath代码

 2 years ago
source link: https://blog.csdn.net/nokiaguy/article/details/120679651
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Python爬虫编程思想(45):在Chrome中自动获得XPath代码

专栏收录该内容
48 篇文章 2 订阅 ¥29.90 ¥99.00

        尽管XPath代码写起来要比正则表达式简单得多,但如果遇到复杂的节点,仍然写起来比较费劲,幸好很多浏览器提供了自动获取XPath代码的能力。我们可以在自动获取的XPath代码的基础上修改,甚至很多时候不需要修改就可以直接使用。本节用Chrome浏览器来演示如何获取特定节点的XPath代码。

        下面的例子在Chrome浏览器中通过开发者工具获取京东商城首页与导航条对应的XPath代码,并稍加修改,然后利用requests库抓取导航条文本。

现在进入京东商城首页(https://www.jd.com),导航条如图1所示黑框中的内容。

        在页面右键菜单中单击“检查”菜单项显示开发者工具,然后定位到导航条的某一个链接(如“秒杀”


Recommend

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK