python selenium库的使用(控制已打开的网页)
'''//windows cd到chrome所在的文件夹下,再以debug模式启动chrome.exe --remote-debugging-port=9527 --user-data-dir=“D:\pycharm\zdh_rxy"--remote-debugging-port远程控制接口--user-data-dir为项目目录'''from selenium import webdriverf
·
- 查看本地安装的chrome浏览器版本,点击chrome浏览器帮助-->关于google chrome,比如博主chrome浏览器版本为
Chrome 已是最新版本
版本 101.0.4951.67(正式版本) (64 位)
- 在chromedriver下载网址中找到对应的驱动:
http://chromedriver.storage.googleapis.com/index.html
http://chromedriver.storage.googleapis.com/index.html 如果没有完全一致的版本,就选择最相近的,比如博主选的“Index of /101.0.4951.41/”,在后续的使用中完全没问题。放置一个固定的目录下,后面创建chromedriver使用,比如博主放在C:\Program Files (x86)\Google\Chrome\Application\chromedriver.exe
- 然后进入chrome所在的文件夹下(右击chrome浏览器,打开所在文件夹),shift+右键打开命令行,运行如下:
chrome.exe --remote-debugging-port=9527 --user-data-dir=“D:\pycharm\zdh_rxy"
--remote-debugging-port远程控制接口,端口后续要用到 --user-data-dir为项目目录 即可登陆你想登陆的网站,后续可直接控制该已打开的网页。
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
import time
import 观看
options = Options()
options.add_experimental_option("debuggerAddress", "127.0.0.1:9527")
# chromedriver驱动所在目录
chromedriver = "C:\Program Files (x86)\Google\Chrome\Application\chromedriver.exe"
s = Service(chromedriver)
browser = webdriver.Chrome(service=s, options=options)
while(True):
(控制代码段。。。)
魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。
更多推荐

所有评论(0)