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:

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"

Leave a Reply