python-3.x - 重新连接硒以打开会话
问题描述
我是新来的
我在 geckobrowser 或 chrome 浏览器中重新连接会话时遇到 selenium 问题
我使用了重用表单 chromebrowser,我有这个错误
root@vps685-8lryq:/var/www/html/coin# python3 test3.py
6d77295243d88243e56f807cb8a3c381
http://127.0.0.1:40785
Traceback (most recent call last):
File "test3.py", line 31, in <module>
driver2 = ReuseChrome(command_executor=executor_url, session_id=session_id)
NameError: name 'ReuseChrome' is not defined
我已经安装了 chromium 和 chromebrowser 并且没有其他问题,它只是重用不起作用:/
from selenium.webdriver.chrome.options import Options
from pyvirtualdisplay import Display
display = Display(visible=0, size=(1024, 768))
display.start()
options = Options()
options.add_argument('--no-sandbox')
options.add_argument('--disable-dev-shm-usage')
options.add_argument('--headless')
options.add_argument('--disable-dev-shm-usage')
options.add_argument("--disable-notifications")
options.add_argument("--disable-gpu")
# The first time you use Chrome () New browser session
driver = webdriver.Chrome( chrome_options=options)
# Record executor_url and to reuse session session_id
executor_url = driver.command_executor._url
session_id = driver.session_id
# Access Baidu
driver.get("http://www.spiderpy.cn/")
print(session_id)
print(executor_url)
# If the driver object does not exist, but the browser is not closed
del driver
# Use ReuseChrome () multiplexing the last session
driver2 = ReuseChrome(command_executor=executor_url, session_id=session_id)
# Print current_url to Baidu's address, indicating reuse successful
print(driver2.current_url)
driver2.get("https://www.baidu.com")
我测试了其他解决方案:
https://tarunlalwani.com/post/reusing-existing-browser-session-selenium/
这个解决方案工作只是我不理解所有代码,但我需要使用 2 个文件
1个原始浏览器启动文件
1 个文件用于在会话中重新连接
对不起我的英语我是法国人
帮我恳求 2 天我试着跑好这个;/
非常感谢你
解决方案
推荐阅读
- angular - 如何通过使用材料表创建列来添加 HTML 代码
- javascript - 查找在angular6中登录的用户ID
- facebook-graph-api - 如何在 Google App 脚本中使用 UrlFetch 获取 Facebook 页面提要的内部字段?
- java - 检查对象列表是否包含Java中的另一个对象
- ios - 如何使用 REST API 或 SDK 将 iOS APNs 身份验证令牌上传到 Firebase?
- powerbi - Power BI - Aurora RDS Postgres 安全性
- node.js - 无法在命令提示符节点版本 11.2.0 中安装 npm 包
- ios - 使用 Cloud Firestore rest api 进行身份验证
- c - 使用编译错误搜索 C 函数定义
- apache-spark - Kotlin 从 cli 编译 - 未解决的参考