Ask coding questions

← Back to all posts
How do i use BS4? (PYTHON
AzureScripts

soup = BeautifulSoup(results_page.content(), 'html.parser')
Is my line of code

Traceback (most recent call last):
File "main.py", line 13, in <module>
soup = BeautifulSoup(results_page.content(), 'html.parser')
TypeError: 'bytes' object is not callable

is the error code

Answered by 21natzil [earned 5 cycles]
View Answer
Voters
AbhayTP
AzureScripts
Comments
hotnewtop
21natzil

This is an issue with the requests library you're using. the content attribute is not a function, but bytes containing the website's response. But instead of passing .content into BS4, you should instead use .text which is a string. So it'd look like

AzureScripts

@21natzil Oh cheers!

Deadly_Venom

results_page <-- is this variable a valid requests object?

AzureScripts

@Deadly_Venom yes.

URL = "https://www.google.com/search?q=" + lyric_query

results_page = requests.get(URL)

Deadly_Venom

@AzureScripts oh wait why r u calling the function, just use result_page.content