Question: IT 280 Lab #7: Link Verification Lab Instructions Program Inputs: Ask the user for the url of a web page. Program Processing: Download every link

IT 280 Lab #7: Link Verification Lab

Instructions

Program Inputs:

Ask the user for the url of a web page.

Program Processing:

Download every link on the page.

Program Output:

Print a list of broken links and a list of good links. This can be printed as the links are downloaded.

Link name 1: Broken

Link name 2: Broken

Link name 3: Good

Link name 4: Broken

Etc.

Here is the code I have so far, but it is not running as it should. Please correct/fix it for me to accomplish the task outlined above:

# Ask user for the url of the web page

url = input("Enter the url of the web page: ")

# Get the html of the web page

response = requests.get(url)

html = response.content

# Parse the html using BeautifulSoup

soup = BeautifulSoup(html, 'html.parser')

# Find all the links on the web page

links = soup.find_all('a')

# Initialize lists for broken and good links

broken_links = []

good_links = []

# Iterate through the links and check their status

for link in links:

try:

# Try to request the link

response = requests.get(link['href'])

# If the link is valid, add it to the good links list

if response.status_code == 200:

good_links.append(link['href'])

except:

# If an exception is thrown, add the link to the broken links list

broken_links.append(link['href'])

# Print the list of broken links

print("Broken links:")

for link in broken_links:

print(link)

# Print the list of good links

print("Good links:")

for link in good_links:

print(link)

Please correct/fix my coding to perform the task mentioned above in light of the above information, then send a screenshot of the code in python.

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!