木三136 2021-03-30 11:07 采纳率: 78.9%
浏览 1095
已结题

使用 selenium接管浏览器 时遇到的问题

这是代码

#-*- coding: utf-8 -*-
import os
import json

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


class ZhiHu:
    def __init__(self):
        self.url = 'https://www.zhihu.com/'
        self.chrome_options = Options()
        self.chrome_options.add_experimental_option("debuggerAddress", "127.0.0.1:9222")  #  前面设置的端口号
        self.browser = webdriver.Chrome(executable_path='../chromedriver.exe', options=self.chrome_options)  # executable执行webdriver驱动的文件

    def get_start(self):
        self.browser.get(self.url)
        info = self.browser.get_cookies()  # 获取cookies
        print(info)
        with open(r"info.json", 'w', encoding='utf-8') as f:
            f.write(json.dumps(info))

        self.browser.close()
if __name__ == '__main__':
    os.system('chrome.exe --remote-debugging-port=9222 --user-data-dir="D:\Learn\selenium_data"')
    zhihu = ZhiHu()
    zhihu.get_start()

这是错误提示


[11768:5712:0330/110048.363:ERROR:external_registry_loader_win.cc(160)] File D:\杞欢\Xdown\xdown\eapmjcdkdlenhkbanlgacimfibbbiinc.crx for key Software\Google\Chrome\Extensions\eapmjcdkdlenhkbanlgacimfibbbiinc does not exist or is not readable.

DevTools listening on ws://127.0.0.1:9222/devtools/browser/f6af029e-e644-4404-a872-4e992da7b162
[11768:9968:0330/110052.869:ERROR:device_event_log_impl.cc(214)] [11:00:52.868] USB: usb_device_handle_win.cc:1056 Failed to read descriptor from node connection: 连到系统上的设备没有发挥作用。 (0x1F)
[11768:9968:0330/110052.870:ERROR:device_event_log_impl.cc(214)] [11:00:52.869] USB: usb_device_handle_win.cc:1056 Failed to read descriptor from node connection: 连到系统上的设备没有发挥作用。 (0x1F)

本来刚开始是能够打开并实现登陆的,但是在后面多试了几次后就不能用了,是因为端口被占用了的原因吗,还是什么原因啊,哪位大佬来帮忙看看,谢谢了 

 

  • 写回答

2条回答 默认 最新

  • 木三136 2021-03-30 14:21
    关注

    原因找到了

    只需将

    os.system('chrome.exe --remote-debugging-port=9222 --user-data-dir="D:\Learn\selenium_data"')

    改为

    os.popen('chrome.exe --remote-debugging-port=9222 --user-data-dir="D:\Learn\selenium_data"')

    即可

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

问题事件

  • 系统已结题 2月11日
  • 已采纳回答 2月3日

悬赏问题

  • ¥15 关于#python#的问题:求帮写python代码
  • ¥15 LiBeAs的带隙等于0.997eV,计算阴离子的N和P
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 来真人,不要ai!matlab有关常微分方程的问题求解决,
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?