The code is as follows:
rom bs4 import BeautifulSoup
import requests
url='XXX'
web=requests.get(url)
soup=BeautifulSoup(web,'lxml')
print(soup)
On these lines, the error is:
E:\Python\Python35-32\python.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:\Python\Python35-32\lib\site-packages\beautifulsoup4-4.5.1-py3.5.egg\bs4\__init__.py", line 192, in __init__
TypeError: object of type 'Response' has no len()
Process finished with exit code 1
Why??
answer
soup=BeautifulSoup(web,'lxml')
There is a mistake in this place. The web here is a response object, which can’t be parsed by using beautiful soup. If you want to parse, the parsing object should be web.content So the correct way to write it is
soup=BeautifulSoup(web.content,'lxml')
Read More:
- TypeError: object of type ‘Cursor‘ has no len()
- TypeError: object of type ‘builtin_function_or_method’ has no len()
- AttributeError: type object ‘Image‘ has no attribute ‘open‘
- Solution: attributeerror: type object ‘ioloop’ has no attribute ‘initialized’
- [Solved] spacy Install Error: AttributeError: type object ‘_CleanResult‘ has no attribute ‘from_link‘
- ERROR 1406 (22001): Data Too Long, field len 30, data len 48
- AttributeError: ‘_io.TextIOWrapper‘ object has no attribute ‘softspace‘
- Attributeerror: object has no attribute
- Debug | AttributeError: ‘numpy.int64‘ object has no attribute ‘to_pydatetime‘
- Python AttributeError: ‘bool‘ object has no attribute ‘ui‘
- AttributeError: ‘Settings’ object has no attribute ‘ROOT_URLCONF’
- AttributeError: ‘PipelinedRDD‘ object has no attribute ‘toDF‘
- Attributeerror: ‘bytes’ object has no attribute’ encode ‘
- AttributeError: ‘NoneType‘ object has no attribute ‘append‘
- AttributeError: ‘WebDriver‘ object has no attribute ‘w3c‘
- AttributeError: ‘Tensor‘ object has no attribute ‘_numpy‘
- Problem: attributeerror: ‘tensor’ object has no attribute ‘creator’
- python gensim AttributeError: ‘Doc2Vec‘ object has no attribute ‘dv‘
- Attributeerror: ‘dataframe’ object has no attribute ‘IX’ error
- AttributeError: ‘NoneType‘ object has no attribute ‘shape‘