div父节点可以返回数据,下面的div则返回空值和td 和 th无法提取数据,烦请老师看看 修改下代码。
import requests
from lxml import etree
headers={
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.121 Safari/537.36'
}
html='https://xyq.cbg.163.com/equip?s=266&eid=202106282000113-266-IUMXACKP7NC3&o&equip_refer=1&view_loc=overall_search|%7B%22tag%22%3A%20%22softmax_fm_slim_with_c_h_price_pdg%22%7D%27'
res=requests.get(url=html,headers=headers)
tree=etree.HTML(res.content,etree.HTMLParser(encoding='gbk'))#解析器加入中文解码
r1=tree.xpath('.//div[@class="tabs"]/ul/li/text()')
r2=tree.xpath('.//div[@class="tabCont" and @id="role_info_box"]')
r3=tree.xpath('.//div[@class="subTab"]')
print(r1)
print(r2)
print(r3)