Sep-30-2023, 02:20 AM
Hello,
I am trying to download a file from a web page, but when I try to open it, it shows an error
This is my code:
Thanks in advance for the help.
I am trying to download a file from a web page, but when I try to open it, it shows an error
This is my code:
session = requests.Session() retries = Retry(total=5, backoff_factor=1, status_forcelist=[500, 502, 503, 504]) session.mount('https://', HTTPAdapter(max_retries=retries)) sw = 1 for row in rows[4:]: if sw == 1: cells = row.find_elements(By.TAG_NAME, "td") if not cells: continue else: image_elements = cells[0].find_elements(By.TAG_NAME, "img") image_to_click = image_elements[0] link_element = cells[0].find_element(By.TAG_NAME, "a") filename = link_element.get_attribute("href") file_2b_downloaded = file_path+ "/" + filename.split("=")[-1] response = requests.get(filename, verify=False) if response.status_code == 200: open(file_2b_downloaded, 'wb').write(response.content) #Creates a folder and move the respective data into it source_file = "C:/Users/"+ username +"/Downloads" destination_folder = fp + "/FO" + rpf[j] if not os.path.exists(destination_folder): os.makedirs(destination_folder) shutil.move(file_2b_downloaded, destination_folder) else: print(f"Failed tp download. Status code: {response.status_code}") sw = 0 else: sw = 1How can I fix this?
Thanks in advance for the help.