我正在嘗試使用 Selenium 自動下載檔案,但當我請求下載檔案時,Google Chrome 會阻止下載。我讀到我需要 user_agent,但不能在我的代碼中作業。
def getting_file(URL):
page = Options()
page.headless = False
service = Service(ChromeDriverManager().install())
driver = webdriver.Chrome(service=service, options=page)
driver.get(url)
driver.get("https://www.rtm.selic.gov.br/extrato-selic-web/pesquisa-extrato-diario-asel.jsp?bust=1662995259495")
time.sleep(5)
driver.find_element(By.CSS_SELECTOR, "tr:nth-child(2) .linkAcao").click()
time.sleep(5)
driver.close()
uj5u.com熱心網友回復:
Chrome 中的常規無頭模式有限制。但是有一個解決方法:
Chromium 開發人員最近添加了第二個無頭模式,其功能與普通 Chrome 相同。
--headless=chrome
(舊方法是:--headless或options.headless = True)
新的無頭模式用法:
options.add_argument("--headless=chrome")
您應該能夠使用該模式并獲得與 Headed 模式相同的結果。
在您的代碼中,更改以下幾行:
page = Options()
page.headless = False
對此:
page = Options()
page.add_argument("--headless=chrome")
這應該為您的情況提供更好的無頭模式。
這里有更多資訊:https ://bugs.chromium.org/p/chromium/issues/detail?id=706008#c36
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/509937.html
標籤:Python硒硒网络驱动程序硒铬驱动程序谷歌浏览器无头
上一篇:已解決:python:selenium.common.exceptions.InvalidArgumentException:訊息:無效引數:無效定位器
