君子好逑 发表于 2020-9-2 15:34:26

爬虫

import requests
from lxml import etree

url = 'http://www.xbiquge.la/modules/article/waps.php'



data = {
    'searchkey':'无敌真寂寞'
}

headers = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.102 Safari/537.36 Edge/18.18363'
}

reponse = requests.post(url=url,headers=headers,data=data)
reponse.encoding = reponse.apparent_encoding
html = reponse.text
# print(html)
tree = etree.HTML(html)

content = tree.xpath('//table[@class="grid"]/tbody//text()')

print(content)

我爬这个网页的时候xpath里不加tbody信息都能打印出来,一加tbody就什么都没了,有大佬能给看一下吗
页: [1]
查看完整版本: 爬虫