简体   繁体   English

使用 Selenium 下载文件时出现“失败 - 下载错误” Python

[英]"Failed - Download error" while download a file using Selenium Python

I was trying to download a file using selenium but getting "Failed - Download error".我尝试使用 selenium 下载文件,但出现“失败 - 下载错误”。

I tried to disable the safe browsing but it didn't work.我试图禁用安全浏览,但没有用。

I have attached the screenshot and code as well.我也附上了屏幕截图和代码。

logs:日志:

DevTools listening on ws://127.0.0.1:53738/devtools/browser/d75dfd5b-1e3e-45c5-8edd-adf77dd9adb1 [2572:2724:0717/104626.877:ERROR:device_event_log_impl.cc(208)] [10:46:26.877] Bluetooth: bluetooth_adapter_winrt.cc:1074 Getting Default Adapter failed. DevTools 侦听 ws://127.0.0.1:53738/devtools/browser/d75dfd5b-1e3e-45c5-8edd-adf77dd9adb1 [2572:2724:0717/104626.877:ERROR:device_event_log_impl.cc(208)] [10:476:26.6.cc] ] 蓝牙:bluetooth_adapter_winrt.cc:1074 获取默认适配器失败。

错误截图

from selenium import webdriver
from selenium.webdriver.support.ui import Select
from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.keys import Keys
import time
import csv
from selenium.webdriver.chrome.options import Options



link_list = [
"stewartwatson.co.uk", 
"peterkins.com", 
"gavin-bain.co.uk", 
"martinco.com", 
"tmmsolicitors.co.uk", 
"corecitilets.co.uk", 
"coxandco.co", 
"dunechtestates.co.uk", 
"bidwells.co.uk", 
"kwad.co.uk",
]

options = webdriver.ChromeOptions()

options.add_experimental_option("prefs", {
  "download.default_directory": r"C:\\Users\\Awais\\projects\\selenium\\web_email_extractor\\csv",
  "download.prompt_for_download": False,
  "download.directory_upgrade": True,
  "safebrowsing.enabled": False,
  "safebrowsing.ebabled": "false"
})

driver = webdriver.Chrome(chrome_options=options)


driver.get("https://www.webemailextractor.com")

try:
    driver.find_element_by_xpath('//button[contains(text(),"Close")]').click()
except:
    pass


for i in link_list[0:5]:
    text_area = driver.find_element_by_xpath('//textarea[@placeholder="Enter domain/websites list"]')
    text_area.send_keys(i)
    text_area.send_keys(Keys.ENTER)

submit = driver.find_element_by_xpath('//input[@value="Extract Email"]').click()
try:
    btn = WebDriverWait(driver, 50).until(EC.element_to_be_clickable((By.XPATH, "//span[contains(text(), ' Process Completed')]")))
    time.sleep(3)
    csv_download = driver.find_element_by_xpath('//button[@class="dt-button buttons-csv buttons-html5"]').click()
except Exception as e:
    print(e)

It worked when I removed the "r" from the path当我从路径中删除“r”时它起作用了

"download.default_directory": r"C:\\Users\\Awais\\projects\\selenium\\web_email_extractor\\csv",

to:到:

"download.default_directory": "C:\\Users\\Awais\\projects\\selenium\\web_email_extractor\\csv",

I was trying to download a file using selenium but getting "Failed - Download error".我试图使用 selenium 下载文件,但出现“失败 - 下载错误”。

I tried to disable the safe browsing but it didn't work.我试图禁用安全浏览,但它不起作用。

I have attached the screenshot and code as well.我也附上了截图和代码。

logs:日志:

DevTools listening on ws://127.0.0.1:53738/devtools/browser/d75dfd5b-1e3e-45c5-8edd-adf77dd9adb1 [2572:2724:0717/104626.877:ERROR:device_event_log_impl.cc(208)] [10:46:26.877] Bluetooth: bluetooth_adapter_winrt.cc:1074 Getting Default Adapter failed. DevTools 监听 ws://127.0.0.1:53738/devtools/browser/d75dfd5b-1e3e-45c5-8edd-adf77dd9adb1 [2572:2724:0717/104626.877:ERROR:device_event_log_impl.cc(208)] [10:46:26.877 ] 蓝牙:bluetooth_adapter_winrt.cc:1074 获取默认适配器失败。

错误截图

from selenium import webdriver
from selenium.webdriver.support.ui import Select
from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.keys import Keys
import time
import csv
from selenium.webdriver.chrome.options import Options



link_list = [
"stewartwatson.co.uk", 
"peterkins.com", 
"gavin-bain.co.uk", 
"martinco.com", 
"tmmsolicitors.co.uk", 
"corecitilets.co.uk", 
"coxandco.co", 
"dunechtestates.co.uk", 
"bidwells.co.uk", 
"kwad.co.uk",
]

options = webdriver.ChromeOptions()

options.add_experimental_option("prefs", {
  "download.default_directory": r"C:\\Users\\Awais\\projects\\selenium\\web_email_extractor\\csv",
  "download.prompt_for_download": False,
  "download.directory_upgrade": True,
  "safebrowsing.enabled": False,
  "safebrowsing.ebabled": "false"
})

driver = webdriver.Chrome(chrome_options=options)


driver.get("https://www.webemailextractor.com")

try:
    driver.find_element_by_xpath('//button[contains(text(),"Close")]').click()
except:
    pass


for i in link_list[0:5]:
    text_area = driver.find_element_by_xpath('//textarea[@placeholder="Enter domain/websites list"]')
    text_area.send_keys(i)
    text_area.send_keys(Keys.ENTER)

submit = driver.find_element_by_xpath('//input[@value="Extract Email"]').click()
try:
    btn = WebDriverWait(driver, 50).until(EC.element_to_be_clickable((By.XPATH, "//span[contains(text(), ' Process Completed')]")))
    time.sleep(3)
    csv_download = driver.find_element_by_xpath('//button[@class="dt-button buttons-csv buttons-html5"]').click()
except Exception as e:
    print(e)

Dear: When we configure the options of selenium is what will be defined in its configurations and as you write the route so considers it in the first photo you will see a well-configured route and a bad one, note bars there is the difference enter image description here亲爱的: 当我们配置 selenium 的选项时,它的配置中将定义什么,当您编写路线时,请考虑在第一张照片中您会看到配置良好的路线和糟糕的路线,注意吧,输入是有区别的图片说明在这里

enter image description here在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM