【问题标题】:Selenium Python Stay connected on a websiteSelenium Python 在网站上保持联系
【发布时间】:2021-04-07 17:06:29
【问题描述】:
from selenium import webdriver
driver = webdriver.Chrome('way//to//chromedriver.exe')
driver.get("https://www.youtube.com/")

我正在尝试启动 youtube 并已连接到它,但我真的不知道该怎么做,我尝试了一些 cookie 但它不起作用,知道吗?

正确解释:

当我运行此代码时,它会启动 youtube,但我没有连接到我的 youtube 帐户,我处于“访客”模式。 我想要的是连接到 selenium 刚刚启动的浏览器(使用我的谷歌帐户)。 因此,为此,我正在尝试使用 cookie,但现在对我没有任何作用。

【问题讨论】:

  • 请提供适当的解释。对不起!我不清楚您面临的问题。如果您的问题有适当的解释,它将帮助我们解决您的问题
  • @MohamedSulaimaanSheriff 嘿!我刚刚进行了编辑,我尽力解释并尽可能简单。
  • 这可能对你有帮助stackoverflow.com/a/31063104/10858089
  • 非常感谢!!!明天我会发布答案并验证它

标签: python selenium


【解决方案1】:

我刚刚解决了问题!

这是我的代码:

from selenium import webdriver
options = webdriver.ChromeOptions() 
options.add_argument("user-data-dir=C:\\Users\\%username%\\AppData\\Local\\Google\\Chrome\\User Data 2")
driver = webdriver.Chrome(executable_path=path,options=options)
driver.get("https://www.google.com") 

如果这仍然不起作用,这里有一些遇到类似问题的人的链接:

How to load default profile in chrome using Python Selenium Webdriver?

Selenium gives "selenium.common.exceptions.WebDriverException: Message: unknown error: cannot find Chrome binary" on Mac

Selenium with Firefor or Chrome profile

【讨论】:

    【解决方案2】:

    我猜你需要使用这个版本:ChromeDriver 87.0.4280.88

    【讨论】:

    • 嗯,我已经用过了,但是我不工作
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-07-12
    • 2018-11-13
    • 2022-11-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-10
    相关资源
    最近更新 更多