Python使用Xpath轻松爬虫(脑残式)
1.在PyCharm安装lxml.
2.找到源码
3.F12、copy源码的xpath
4.代码
from lxml import etree import requests wb_data = requests.get("https://www.baidu.com/").text html = etree.HTML(wb_data) html_data = html.xpath('//*[@id="lh"]/a[2]'); for i in html_data: print(i.text)