用xpath接下一个tbale,并提取值.
首先安装lxml包
pip3 install lxml
from lxml import etree # 获取返回响应的html文件 response = requests.get(url=url, cookies=cookie) # ElementTree对象 selector = etree.HTML(response.text) # 获得所有的tr trs = selector.xpath('//table[@class="tbl_type4"]/tbody/tr') # 遍历,提取每个td的值 for tr in trs: td1 = tr.xpath('./td[1]/text()')[0].strip() td2 = tr.xpath('./td[2]/a/text()')[0].strip() td3 = tr.xpath('./td[3]/div/a/@title')[0].strip()
文章来源: https://blog.csdn.net/weixin_43784462/article/details/91992394