欢迎光临散文网 会员登陆 & 注册

使用selenium操作指定浏览器

2022-07-31 13:14 作者:限量版范儿  | 我要投稿

selenium操作中最麻烦的就是登录、验证还有代理配置,因此我就想人工把这些工作搞定后再直接用selenium来操作。以chrome为例,简单介绍下步骤:

  1. 首先创建一个文件夹(用来放一些浏览器的文件)
    D:\AutomationProfile\chrome

  2. 找到谷歌浏览器路径(也就是找到你的chrome.exe在哪)
    chrome.exe --remote-debugging-port=9527 --user-data-dir="D:\AutomationProfile\chrome" --proxy-server="xxx.xxx.xxx.xxx:8888"
    这样就启动一个浏览器,你可以现在上面做好登录、验证等等的一些操作。

  3. 启动你的selenium试试吧

from selenium import webdriver WEBDRIVER_PATH = "D:/webdriver/chromedriver.exe" SERVICE_LOG_PATH = "./logs/chromedriver.log" options = webdriver.ChromeOptions() options.add_experimental_option("debuggerAddress", "127.0.0.1:9527") driver = webdriver.Chrome(WEBDRIVER_PATH, options=options, service_log_path=SERVICE_LOG_PATH) driver .get('https://www.cnblogs.com/')


原文链接:https://www.dianjilingqu.com/459464.html

使用selenium操作指定浏览器的评论 (共 条)

分享到微博请遵守国家法律