Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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: 3

blur-text-image

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

Describe your ideal working day.

Answered: 1 week ago