Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Unable to open LOCAL HTML page for scrapping using BS$ Python

I have written following code to open a local HTML file saved on my Desktop:

enter image description here

However while running this code I get following error:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

enter image description here

I have no prior experience of handling this in Python or BS4. I tried various solutions online but couldn’t solve it.

Code:

import csv
from email import header
from fileinput import filename
from tokenize import Name
import requests
from bs4 import BeautifulSoup


url = "C:\  Users\  ASUS\   Desktop\    payment.html"
page=open(url)
# r=requests.get(url)
# htmlContent = r.content
soup = BeautifulSoup(page.read())



head_tag = soup.head
for child in head_tag.descendants:
    print(child)

enter image description here

Need help!

Thank you in advance.

>Solution :

It’s unicode error prefix the path with r (to produce a raw string):

url = r"C:\  Users\  ASUS\   Desktop\    payment.html"
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading