Question: The above coding has the following issues: I get issues when trying to download the image files. When I try running only the parse code,

The above coding has the following issues: I get issues when trying to download the image files. When I try running only the parse code, it gives an error when trying to parse the images. Not all the images have a src attribute, and the program doesn't handle that well. The project asked for all pictures to be displayed after running the program. Please fix the coding issues for me.
LAB 8.1.py Project Preconditions: For this projcct, you will need to install (1/Windows 10 VM Fnvironment., (2) the. internet available, and i3j Python installed. Project Initial Task: Ernsure thal the lollowins methodsi are intiblled: webbrowstr, tyss, anud requests. Jownload and install the BS4 method it.. Program Inputs: The url for 2 whebites: {(1) httos://www. jamaicaobscrwer.com and (2) hllps://wwwensign.edu l Program Proccssing: - Webpage 1: https://www,jamaicaobserver, com will be scheduled to launch in a thread 3 minutes after program cxccution. The program should check for loading crrors if any are found: (lisplay cror and Exit threadi). If no loading error is found: (download all images from the websire). - Wehpage 2: hrtps:// rww.engign.edus will be scheduled to launch in a thread 5 minutes after progrumn execulion. The programn should check for loading errors if uny are found: (Displaty error and Exit thread), If no loading error is tound: (Create a BS4 object and Par'se object for the following tags: , , , - (they may not all be present), then display the resulls). Project Output (if no downlond errors): All images on website 1 are displayed in Paint or another progrum. The resulss of the BS4 parse from website 2 . Project coding so far: This is coding that has been completed so far: import sys import requests import time from bs4 import. HeautifulSoup import threading def download imagesiurl): try: response - requests.netiurl] if responsc.statis_codc ==200 : soup = DeaulifulSoup(response.text, 'html.purser") images = [imgl'sre'] for img in somp.find_all[img']] For i, irmilse in erumerate (imilues): response - rexuests.get(image] openi('irnape fi1 .jpgy", "wb").write(response.content) print['All images downlnaded successfully'] else: prinr('Error: Failed to download images'! except Exception als e: print"'Error":", el def parse bs4url): t.ry: response - requests.getiurl] if responsc.status_codc ==200 : soup - Beautifilsoupiresponse.text, 'html parser') title = soup. title.string if soup.title clsc: "No title found" print('Tille:', Litle) images = [img['sre'] for ing in soup.find_all'img'l] princi'Images:", imagesi time = soup.time.string if soyp.time clse "No time fonnd" prin(l'Tine:', tirnel links = [link['href ] for link in soup.find_alli'a ]] prinul|'Linzks:", linksi videos = [video['src'] for vides in soup_find_all[tideo')] prinl' Videas:', videos) elze: printl'Lror: Failed to parsc: wobsite' except Exception as e: prinli'"Lror:", el \# Schedule the first website to latmch in a thrcad three minutes after program cxecution rhreading.Timeri 180 , download_images, ["https:// wmw.jamaicaobserver.com']], starti] \# Schedule the second website to launch in a thread tive minutes atter program execution rhreading.Timer(300, parse_bs4, ["https:/ / wrwu.cnsign.cdu"]].stait l]
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
