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 @   颜舞撩扰  阅读(627)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
历史上的今天:
2021-06-17 Python上下文管理器
footer
点击右上角即可分享
微信分享提示