Issue: when I try to execute the script, BeautifulSoup(html, ...) gives the error message "TypeError: object of type 'Response' has no len(). I tried passing the actual html as a parameter, but it still doesn't work.
url = "https://www.ximalaya.com/shangye/6855034/"
headers={
'User-Agent':'Mozilla/5.0 (Windows NT 10.0; WOW64; rv:62.0) Gecko/20100101 Firefox/62.0',
}
html=requests.get(url,headers=headers)
html.encoding = 'utf-8'
# print(html.text)
soup = BeautifulSoup(html.text, 'html.parser')
# soup = BeautifulSoup(html, 'html.parser'),传入参数html不行哦
print(soup.text)
https://stackoverflow.com/questions/36709165/beautifulsoup-object-of-type-response-has-no-len
本文探讨了在使用Python的BeautifulSoup和requests库时遇到的一个常见错误:TypeError: object of type 'Response' has no len()。作者尝试了将html作为参数传递给BeautifulSoup,但仍然无法解决问题。文中提供了具体的代码示例,包括请求URL、设置headers以及尝试解析HTML的代码。
4026

被折叠的 条评论
为什么被折叠?



