zhouxn921031
zhouxn921031
2020-11-25 17:09
采纳率: 0%
浏览 68

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

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • qqzhuimengren
    PythonJavaC++go 2020-11-25 17:32

    text 改为text.content或者str(text)

    点赞 评论
  • weixin_50590724
    猪猪_女孩 2020-11-25 21:59

    carlist是个文件,这样获取不到

    点赞 评论

相关推荐