Search code examples
pythonwebbeautifulsouppython-requestsscreen-scraping

Using Beautifulsoup gives a ResultSet object upon instantiation


I am trying to use beautifulsoup, but when I instantiate it with an html object, it is saying that it is a ResultSet object and any methods I try to run fail with an AttributeError.

bs = BeautifulSoup()
soup = bs(response.text, 'html.parser')
type(bs) == type(soup)

False

I have tried with response.content and gotten the same result, and haven't been able to find this exact issue yet from other questions.


Solution

  • You are instantiating an empty BeautifulSoup object with the first line of your code. Your second line of code returns an empty resultset as a result. Instead, you want to do this:

    soup = BeautifulSoup(response.text, 'html.parser')