【问题标题】:how do I acces whatsapp web with selenium in python?如何在 python 中使用 selenium 访问whatsapp web?
【发布时间】:2020-10-16 01:58:58
【问题描述】:

所以我使用 geckodriver.exe(用于 Firefox),并使用以下代码访问 whatsapp 网页:

from selenium import webdriver
browser = None
def init():
    browser = webdriver.Firefox(executable_path=r"C:/Users/Pascal/Desktop/geckodriver.exe")
    browser.get("https://web.whatsapp.com/")
init()

但是每次我重新运行代码时,都必须再次扫描来自 whatsappweb 的二维码,我不希望这样。在我的普通 chrome 浏览器中,我不必每次都扫描 QR 码。我该如何解决这个问题?

【问题讨论】:

    标签: python selenium testing automated-tests


    【解决方案1】:

    由于每次关闭 selenium 驱动程序/浏览器时,会话附带的 cookie 也将被删除。因此,要恢复您保存的 cookie,您可以在会话结束后检索它并在下一次开始时恢复它。

    为了获取 cookie,

    # Go to the correct domain, i.e. your Whatsapp web
    browser.get("https://www.example.com")
    # get all the cookies from this domain
    cookies = browser.get_cookies()
    # store it somewhere, maybe a text file
    

    用于恢复 cookie

    # Go to the correct domain, i.e. your Whatsapp web
    browser.get("https://www.example.com")
    # get back the cookies
    cookies = {‘name’ : ‘foo’, ‘value’ : ‘bar’}
    browser.add_cookies(cookies)
    

    【讨论】:

    • 不幸的是它没有用。没有 cookie...
    猜你喜欢
    • 2018-11-20
    • 1970-01-01
    • 2011-12-28
    • 2018-07-09
    • 2018-05-19
    • 2019-05-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多