
最近有个需求,就是拿到一个网页的源代码,然后找到其中元素对应的 XPath ,在 Python 中完成。
类似于 Chrome 中的"Copy XPath"功能。
伸手党想问一下有没有现成的 Python 库可以解决?
1 leisurelylicht 2016 年 1 月 14 日 from lxml import etree 或者 beautifulsoup |
2 exploitcat OP @leisurelylicht 有没有 demo 呢? 可以获取指定 element 的 xpath ? |
3 bdbai 2016 年 1 月 14 日 via iPhone 楼上说的是通过 XPath 选择元素吧。 为什么要用 Python 生成 XPath ?如何确定是哪一个元素? |
4 |
5 exploitcat OP @bdbai 需求往往不需要解释。。。。 |
6 leisurelylicht 2016 年 1 月 15 日 @exploitcat 好像没有,需要你自己生成 |
7 wwxiong 2016 年 1 月 15 日 @exploitcat 可以看看 https://github.com/wwxiong/spiders/blob/master/meizi_spider.py 爬虫。里面就是使用 lxml 。 |
8 ruiruirui 2019 年 12 月 10 日 楼主是如何解决这个问题的,我现在也有个这么一个需求。 |