Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_step_2

Step: 3

blur-text-image_step3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

Different formulas for mathematical core areas.

Answered: 1 week ago

Question

1. Write down two or three of your greatest strengths.

Answered: 1 week ago