程序员最近都爱上了这个网站  程序员们快来瞅瞅吧!  it98k网:it98k.com

本站消息

站长简介/公众号

  出租广告位,需要合作请联系站长

+关注
已关注

分类  

python面试大全(3)

python前言(0)

标签  

python面试(2)

python(0)

日期归档  

【异常处理】TypeError: object of type 'Response' has no len()

发布于2019-10-29 17:49     阅读(6265)     评论(0)     点赞(24)     收藏(1)


TypeError: object of type ‘Response’ has no len()

hmtl=requests.get(‘http://shakespeare.mit.edu/hamlet/hamlet.1.1.html’)
hmtl.raise_for_status()
hmtl.encoding=‘iso-8859-1’
soup = BeautifulSoup(hmtl, ‘lxml’)

Traceback (most recent call last):
File “D:/python/Python37/untitled1/0.py”, line 7, in
soup = BeautifulSoup(hmtl, ‘lxml’)
File “D:\python\Python37\lib\site-packages\bs4_init_.py”, line 275, in init
elif len(markup) <= 256 and (
TypeError: object of type ‘Response’ has no len()

错误原因是BeautifulSoup库不能解析response类型,只需要将hmtl变量的text赋值给新变量然后解析,或者直接:
soup = BeautifulSoup(hmtl.text, ‘lxml’)

以上.



所属网站分类: 技术文章 > 博客

作者:骷髅无悔

链接:https://www.pythonheidong.com/blog/article/147741/1d9d792b143b5deadb00/

来源:python黑洞网

任何形式的转载都请注明出处,如有侵权 一经发现 必将追究其法律责任

24 0
收藏该文
已收藏

评论内容:(最多支持255个字符)