Python+Selenium浏览器自动化操作

1.安装selenium

pip install selenium # Windows
pip3 install selenium # Mac

2.下载浏览器驱动

下载地址:https://chromedriver.chromium.org/downloads


注意浏览器版本

将下载好的chromedriver_win32.zip解压得到一个chromedriver.exe文件,将其复制到你的Python程序执行路径。



3.启动 Chrome浏览器的调试模式

chrome.exe --remote-debugging-port=9222



4.示例代码

from selenium import webdriver
from selenium.webdriver.chrome.options import Options

配置 = Options()
配置.debugger_address = 'localhost:9222'
驱动位置 = "./Data/chromedriver.exe" #我是把chromedriver驱动放在项目根目录下
浏览器 = webdriver.Chrome(驱动位置, chrome_options=配置)
print(浏览器.title)
展开阅读全文

页面更新:2024-06-02

标签:浏览器   根目录   示例   路径   命令   位置   版本   模式   操作   代码   文件

1 2 3 4 5

上滑加载更多 ↓
推荐阅读:
友情链接:
更多:

本站资料均由网友自行发布提供,仅用于学习交流。如有版权问题,请与我联系,QQ:4156828  

© CopyRight 2020-2024 All Rights Reserved. Powered By 71396.com 闽ICP备11008920号-4
闽公网安备35020302034903号

Top