MikeWen07
2022-07-01 17:07
采纳率: 100%
浏览 21

使用xpath爬取时打印输出"[]"

问题遇到的现象和发生背景

python使用xpath爬取时打印输出"[]"

问题相关代码
import requests
from lxml import etree

url = 'https://movie.douban.com/chart'
headers = {'User-Agent':'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36'}
rs = requests.get(url,headers=headers)
rs=rs.text

e1 = etree.HTML(rs)

info = e1.xpath("/html/body/div[@id='wrapper']/div[@id='content']/div[@class='grid-16-8 clearfix']/div[@class='article']/div[@class='indent']/div/table/tbody/tr/td/div/a/text()")


print(info)
运行结果及报错内容

[]

怎么输出正确结果

1条回答 默认 最新

相关推荐 更多相似问题