python - 为什么 Selenium chromedriver 不添加配置文件?
问题描述
我正在尝试将 chrome 配置文件添加到我的程序中,但它什么也没做。有人可以帮忙吗?
我正在使用 Selenium python。当我运行时,它似乎忽略了这些语句并在临时配置文件中运行。
import time
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
import random
import string
from selenium.webdriver.chrome.options import Options
while True:
emailstarter = random.randint(11111111111111111111,999999999999999999999)
first = random.randint(666666,888888)
last = random.randint(555,55555)
driver = webdriver.Chrome(r"C:\Program Files (x86)\chromedriver.exe") # Optional argument, if not specified will search path.
options = webdriver.ChromeOptions()
options.add_argument("user-data-dir=C:\\Users\\user\\AppData\\Local\\Google\\Chrome\\User Data\\Default");
解决方案
你的顺序错了。您应该首先创建选项,然后将它们作为参数传递给webdriver.Chrome
类:
from selenium import webdriver
options = webdriver.ChromeOptions()
options.add_argument("user-data-dir=C:\\Users\\user\\AppData\\Local\\Google\\Chrome\\User Data\\Default");
driver = webdriver.Chrome(
executable_path=r"C:\Program Files (x86)\chromedriver.exe",
options=options
)
推荐阅读
- reactjs - 从页面上的数据动态创建 pdf 并使用 React mailgun 和 jsPDF 通过电子邮件发送
- firebase - 如何在glightbox中禁用缩放图像?
- java - 没有 UDF/UDAF/UDTF 的处理程序 - Spark UDF3
- javascript - 有没有办法将 JavaScript array.find 输出调节到二维数组中的某些“类别”?
- php - “必需”属性在 PHP HTML 中不起作用
- javascript - 在 node.js 中将 .voc 音频转换为 wav
- php - 致命错误:在 null 上调用成员函数 query() - 仅在本地服务器上的 Web 服务器上没有问题
- enums - 为什么字符串不是 Elixir 中的枚举?
- javascript - 扩展运算符 ES5 等效
- elasticsearch - 如何将特定格式的文档导入 Elasticsearch?