python - 使用 selenium python 和 Firefox 重新打开相同的浏览器窗口

标签 python selenium firefox webdriver selenium-chromedriver

嘿,我正在尝试制作一个自动程序来发送 Whatsapp 消息。 我目前正在使用 python、Firefox 和 selenium 来实现这一目标。 问题是每次我调用 driver.get(url) 它都会打开一个新的 firefox 浏览器实例,空白,没有上次运行的内存。它让我每次运行时都扫描条形码。

from selenium import webdriver
from selenium.webdriver.firefox.webdriver import FirefoxProfile

cp_profile = webdriver.FirefoxProfile("/Users/Hodai/AppData/Roaming/Mozilla/Firefox/Profiles/v27qat5d.whatsapp_profile")
driver = webdriver.Firefox(executable_path="/Users/Hodai/Desktop/geckodriver",firefox_profile=cp_profile)
driver.get('http://web.whatsapp.com')

#Scan the code before proceeding further
input('Enter anything after scanning QR code')

我试过使用配置文件,但似乎没有任何影响。

cp_profile = webdriver.FirefoxProfile("/Users/Hodai/AppData/Roaming/Mozilla/Firefox/Profiles/v27qat5d.whatsapp_profile")
driver = webdriver.Firefox(executable_path="/Users/Hodai/Desktop/geckodriver",firefox_profile=cp_profile)

最佳答案

最后我使用 chromedriver 来实现我的目标。 我尝试用 pickle 做 cookies,但这有点棘手,因为它只记住同一个域的 cookies。 所以我使用了 chrome 的用户数据。 现在它就像一个魅力。谢谢大家。

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

options = Options()
options.add_argument("user-data-dir=C:/Users/Designer1/AppData/Local/Google/Chrome/User Data/Profile 1")
driver = webdriver.Chrome(chrome_options=options,executable_path="C:\webdrivers\chromedriver.exe")

关于python - 使用 selenium python 和 Firefox 重新打开相同的浏览器窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50400666/

相关文章:

python - 如何使用 __init__.py 在 python 中导入包

python - 在多处理进程之间将opencv视频帧共享为Numpy数组的正确方法

python - 在 Python 3 解释器模式下粘贴代码时出现 IndentationError

php - Selenium RC 通过 (winxp/winserver) 发送空白屏幕截图

javascript - 如何读取元素值和点击时间量

javascript - 搜索选择器时出现意外的文件结尾。由于选择器错误而忽略规则集

python - pyodbc 没有更新表

java - Selenium 和 TestNG 都在一个浏览器中测试

javascript - jQuery animate 在 Firefox 中实现 div 跳跃

javascript - Firefox 和 IE6 的 document.ready() 问题