Python etree 问题

按照视频教学打的一模一样的代码,我的就是报错。。。

代码如下

import requests
from lxml import etree
headers = {
此处略过
}
url = 'https://www.guazi.com/cs/buy/o1/'

resp = requests.get(url,headers=headers)
text = print(resp.content.decode('utf-8'))
html = etree.HTML(text)
ul = html.xpath('//ul[@class="carlist clearfix js-top"]')
print(ul)

报错内容:

Traceback (most recent call last):
  File "C:/Users/Ryu/PycharmProjects/pythonProject1/Webauto.py", line 11, in <module>
    html = etree.HTML(text)
  File "src\lxml\etree.pyx", line 3185, in lxml.etree.HTML
  File "src\lxml\parser.pxi", line 1895, in lxml.etree._parseMemoryDocument
ValueError: can only parse strings

查看全部
zhouxn921031
zhouxn921031
2020/11/25 17:09
  • python
  • 点赞
  • 收藏
  • 回答
    私信

2个回复