当我尝试执行代码时
BeautifulSoup(html, ...)
它给出了错误信息
TypeError: object of type 'Response' has no len()
我尝试将实际的 HTML 作为参数传递,但它仍然不起作用。
import requests
url = 'http://vineoftheday.com/?order_by=rating'
response = requests.get(url)
html = response.content
soup = BeautifulSoup(html, "html.parser")
最佳答案
您正在获取 response.content
。但它以字节(docs)的形式返回响应正文。但是您应该将 str
传递给 BeautifulSoup 构造函数 ( docs )。所以你需要使用 response.text
而不是获取内容。
关于python - "TypeError: object of type ' 响应 ' has no len()",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36709165/