【问题标题】:get_cookies() returns empty list with Whatsapp web using Chrome in Seleniumget_cookies() 在 Selenium 中使用 Chrome 返回带有 Whatsapp Web 的空列表
【发布时间】:2020-04-29 01:33:14
【问题描述】:

我正在尝试为 Whatsapp 保存我的 cookie,这样我就可以运行我的程序,而不必每次都扫描 QR 码。

使用以下代码时,登录 Whatsapp 后 cookie 会返回一个空列表

from selenium import webdriver
import time

browser = webdriver.Chrome()
browser.get('https://web.whatsapp.com/')

time.sleep(10) #give me enough time to scan the QR code

cookies = browser.get_cookies()
print cookies

我不知道为什么应该存在的 cookie 没有出现。 (确实会显示 google.com 的 cookie。)

在这种情况下,我不能使用 user-data-dir 参数,因为我将无头运行它,任何其他建议都会有所帮助。

【问题讨论】:

    标签: python selenium google-chrome cookies whatsapp


    【解决方案1】:

    一旦您登录,您的会话将默认存储在 google-chrome 上,您可以使用用户数据导入相同的设置和 cookie。这不需要您再次登录。

    chrome-user-path 模板 ** C:\Users\\AppData\Local\Google\Chrome\User Data\Default**

    from selenium import webdriver
    
    options = webdriver.ChromeOptions()
    options.add_argument(user_profile_path)
    driver = webdriver.Chrome( executable_path="chromedriver", chrome_options=options)
    driver.get( "https://api.WhatsApp.com/send?phone={}".format(phone_number)) 
    

    这对我有用,你也可以查看这个repo,代码有点过时,但稍作调整就可以了

    【讨论】:

      猜你喜欢
      • 2014-02-05
      • 2021-10-27
      • 1970-01-01
      • 1970-01-01
      • 2020-05-09
      • 2016-03-31
      • 1970-01-01
      • 2014-09-16
      相关资源
      最近更新 更多