I noticed sth about python while using the beautifulsoup module, local html files using with open don't open correctly
Using the requests module, if I want to work on anything using the bs4 module and write a code like the one below, it works just fine.
billboard_page_html = requests.get("https://www.billboard.com/charts/hot-100/2024-05-04/")
soup = BeautifulSoup(billboard_page_html.text, 'html.parser')
For the webpage above, I saved the html of the webpage as a file, when I view the saved html file through an IDE/browser, everything works fine, but when I try write code by accessing the saved file, I get issues.
Below is an example where I tried to print out the saved html file.
with open("Billboard_Data.html") as file:
contents = file.readlines()
print(contents)
When I printed contents, the output I got isn't what I expected, I got this - 1st image. What you see in Image1 is the beginning of the file not the whole thing, when I try to run it through bs4 through a code like this
with open("Billboard_Data.html") as file:
contents = file.readlines()
soup = BeautifulSoup(contents, 'html.parser')
I get the error code TypeError: expected string or bytes-like object, got 'list'
Don't know if its useful, but if anyone wants the full error code - https://pastebin.com/eMrXks3m
The second image is a cutout of the beginning of the html file I saved on my pc. Looking at it, it looks like a normal html file, it starts with <!DOCTYPE html> and the likes. The 1st image is the output I get when I try to open it locally on python which is giving me an issue and doesn't come out in the right format.
Is there a way for me to open files on python and have it open in the right format? There are times when I want to use a local html file instead of getting it directly from the web.
This is the code I'm writing - https://pastebin.com/f1fDnAeF
It's a WIP, I'm trying to make a program that gets the top 100 charting songs on Billboard.
