【问题标题】:Cannot open up URL with selenium python, but the browser is succesfully opened无法用selenium python打开URL,但浏览器成功打开
【发布时间】:2020-11-18 06:31:31
【问题描述】:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.keys import Keys
import time
import datetime


ch_options = webdriver.ChromeOptions()
ch_options.add_argument("--user-data-dir=C:\\Users\\Dossy\\AppData\\Local\\Google\\Chrome\\User Data")


chrome = webdriver.Chrome(options=ch_options)

chrome.get("https://www.google.com/")

此代码仅使用我的个人资料打开 chromedriver,但无法重定向到链接

【问题讨论】:

    标签: python python-3.x selenium selenium-webdriver webdriver


    【解决方案1】:

    用正确的驱动路径试试这个

    from selenium import webdriver
    from selenium.webdriver.chrome.options import Options
    from selenium.webdriver.common.keys import Keys
    import time
    import datetime
    
    chromedriver = 'path of chrome driver till chromedriver.exe'
    driver = webdriver.Chrome(chromedriver)
    driver.get("https://www.google.com/")
    
    

    【讨论】:

      【解决方案2】:

      让它变得如此简单和简短: 确保正确添加chrome驱动路径

      from selenium import webdriver
      from selenium.webdriver.chrome.options import Options
      from selenium.webdriver.common.keys import Keys
      import time
      import datetime
      
      PATH = r"C:\Program Files (x86)\chromedriver.exe"    # Path where u have downloaded the driver
      
      driver = webdriver.Chrome(PATH)
      
      driver.get("https://www.google.com")
      

      希望这会奏效!

      【讨论】:

      • 我尝试了PATH = r"C:\PATH\to\chromedriver.exe" ,但它没有使用我的 Chrome 用户配置文件,而是使用 Chrome 访客帐户
      【解决方案3】:

      而不是这样写:

      ch_options = webdriver.ChromeOptions()
      ch_options.add_argument("--user-data-dir=C:\\Users\\Dossy\\AppData\\Local\\Google\\Chrome\\User Data")
      

      你可以直接给出路径

      ch_options = webdriver.Chrome('**HERE GIVE  YOUR FULL PATH OF chromedriver.exe**')
      

      喜欢:

      chrome = webdriver.Chrome('C:\\Users\\Lucky\\Downloads\\.zip\\chromedriver.exe')
      

      您的浏览器将打开,它还会将您重定向到该链接。

      【讨论】:

      • 我试过chrome = webdriver.Chrome('C:\\Users\\Lucky\\Downloads\\.zip\\chromedriver.exe'),但它不使用我的个人资料,它使用来宾帐户
      【解决方案4】:

      如果您在第一个解决方案中遇到问题,请尝试以下操作: 首先复制chrome驱动路径:

      然后,转到“这台电脑”并右键单击它,然后转到属性:

      进入高级系统设置后:

      然后,点击环境变量

      然后,在系统变量中单击路径,然后单击编辑:

      然后,点击新建:

      之后,用 \chromedriver.exe 粘贴复制的路径,然后点击“确定”:

      然后在所有选项卡上单击“确定” 就是这样 现在试试 如果您对此仍有问题,请发表评论。

      【讨论】:

      • 如果有问题评论下试试这个。
      猜你喜欢
      • 1970-01-01
      • 2018-04-01
      • 2021-06-10
      • 2018-02-01
      • 2017-08-01
      • 2017-03-25
      • 2020-08-13
      • 2021-01-20
      • 1970-01-01
      相关资源
      最近更新 更多