home

使用selenium操作指定浏览器

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/')
posted @ 2022-06-17 15:24  颜舞撩扰  阅读(612)  评论(0编辑  收藏  举报
footer