Question: I needed to make a Python program that downloads a web page (by download I mean acquire the html, css, js, etc.) and display that

I needed to make a Python program that downloads a web page (by download I mean acquire the html, css, js, etc.) and display that information along with the headers associated with the site. I have some code here that does do what I mentioned for most sites such as youtube.com, yahoo.com, ubereats.com, etc., but my issue is when I try to run my program on google.com I get this error:

Traceback (most recent call last): File "C:/Users/Admin/PycharmProjects/networking/webDownload.py", line 19, in print('============================== CONTENT OF WEB PAGE ============================== ',content.decode()); UnicodeDecodeError: 'utf-8' codec can't decode byte 0xa0 in position 9793: invalid start byte

Is there any way I can fix this? Here is my current code:

#importing module to access web pages import urllib.request; #getting a web page url from user webPage = input('Enter a web page url: '); #adding http at the beginning if not exists if not webPage.startswith('http'): webPage='http://' + webPage; #finding the response response = urllib.request.urlopen(webPage); #reading the contents of arbitrary web page content = response.read(); #displaying the web page which is the first part of the program print('============================== CONTENT OF WEB PAGE ============================== ',content.decode()); #displaying the header info which is the second part of the program print(' ============================== HEADER INFO ============================== ',response.info());

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!