•  查看本地安装的chrome浏览器版本,点击chrome浏览器帮助-->关于google chrome,比如博主chrome浏览器版本为
Chrome 已是最新版本

版本 101.0.4951.67(正式版本) (64 位)
  • 在chromedriver下载网址中找到对应的驱动:

http://chromedriver.storage.googleapis.com/index.htmlicon-default.png?t=M4ADhttp://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):
    (控制代码段。。。)

Logo

技术共进,成长同行——讯飞AI开发者社区

更多推荐