TypeError:タイプ 'Response'のオブジェクトにlen()がありませんこれが理由ですか?



Typeerror Object Typeresponsehas No Len This Is Why



コードは次のように表示されます。

rom bs4 import BeautifulSoup import requests url='XXX' web=requests.get(url) soup=BeautifulSoup(web,'lxml') print(soup)

これらの行のエラーは次のとおりです。



E:PythonPython35-32python.exe C:/Users/ty/PycharmProjects/untitled3/src/Reptile.py Traceback (most recent call last): File 'C:/Users/ty/PycharmProjects/untitled3/src/Reptile.py', line 7, in <module> soup=BeautifulSoup(web,'lxml') File 'E:PythonPython35-32libsite-packageseautifulsoup4-4.5.1-py3.5.eggs4\__init__.py', line 192, in __init__ TypeError: object of type 'Response' has no len() Process finished with exit code 1

なぜそれを解決するのですか? ?

回答


soup=BeautifulSoup(web,'lxml')

この場所は間違っています。ここのwebは解決できない応答オブジェクトですBeautifulSoup、解析する場合、解析オブジェクトはweb.contentである必要があるため、正しい表現は次のとおりです。



soup=BeautifulSoup(web.content,'lxml')