【问题标题】:Selenium opens web browser but not the target url (InvalidArgumentException: Message: invalid argument)Selenium 打开 Web 浏览器但不打开目标 url (InvalidArgumentException: Message: invalid argument)
【发布时间】:2021-01-20 10:29:25
【问题描述】:

我尝试寻找解决方案,但没有任何效果,所以这是我最后的希望。其他 stackoverflow 案例都不适合我。

我试着跑

from selenium import webdriver
b=webdriver.Chrome()

b.get("www.google.com")

但它只打开一个"data:," 页面,什么都没有。

在终端有

DevTools listening on ws://127.0.0.1:50361/devtools/browser/fef860a9-fd7b-4e53-9367-b7e59b57fa66
Traceback (most recent call last):
  File "c:/Microsoft VS Code/CODES/bot.py", line 4, in <module>
    b.get("www.google.com")
  File "C:\Users\istiak\AppData\Local\Programs\Python\Python38-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 333, in get
    self.execute(Command.GET, {'url': url})
  File "C:\Users\istiak\AppData\Local\Programs\Python\Python38-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
    self.error_handler.check_response(response)
  File "C:\Users\istiak\AppData\Local\Programs\Python\Python38-32\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.InvalidArgumentException: Message: invalid argument
  (Session info: chrome=85.0.4183.121)

这个。解决这个问题的最佳方法是什么? 非常感谢。

【问题讨论】:

标签: python selenium selenium-webdriver


【解决方案1】:

.get() 参数必须是有效的格式化 url,查看 docs 时会得到 InvalidArgumentException

传递给命令的参数无效或格式错误。

尝试将http://https:// 添加到您的webdriver.get(),因为Selenium 认为以www... 开头的网址无效:

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

【讨论】:

  • 我现在觉得自己很蠢……非常感谢。为此,我度过了一个不眠之夜。 :(
猜你喜欢
  • 1970-01-01
  • 2020-08-13
  • 2017-03-25
  • 2017-03-04
  • 1970-01-01
  • 1970-01-01
  • 2018-04-01
  • 2017-07-14
  • 2017-07-26
相关资源
最近更新 更多