使用selenium操作指定浏览器
selenium操作中最麻烦的就是登录、验证还有代理配置,因此我就想人工把这些工作搞定后再直接用selenium来操作。以chrome为例,简单介绍下步骤:
- 首先创建一个文件夹(用来放一些浏览器的文件)
D:\AutomationProfile\chrome
- 找到谷歌浏览器路径(也就是找到你的chrome.exe在哪)
chrome.exe --remote-debugging-port=9527 --user-data-dir="D:\AutomationProfile\chrome" --proxy-server="xxx.xxx.xxx.xxx:8888"
这样就启动一个浏览器,你可以现在上面做好登录、验证等等的一些操作。 - 启动你的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/')
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
2021-06-17 Python上下文管理器