When I try to execute the code
BeautifulSoup(html, ...)
it 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.
import requests
url = 'http://vineoftheday.com/?order_by=rating'
response = requests.get(url)
html = response.content
soup = BeautifulSoup(html, "html.parser")
You are getting response.content
. But it return response body as bytes (docs). But you should pass str
to BeautifulSoup constructor (docs). So you need to use the response.text
instead of getting content.
Try to pass the HTML text directly
soup = BeautifulSoup(html.text)
html.parser
is used to ignore the warnings in the page:
soup = BeautifulSoup(html.text, "html.parser")
If you're using requests.get('https://example.com')
to get the HTML, you should use requests.get('https://example.com').text
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With