添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

Yeni bilgisayara geçtim ama bu pc de selenium çalıştıramıyorum. İnternetten hiçbir şey bulmadım.

import selenium
from selenium import webdriver
driver_path = r"C:\chromedriver.exe"
browser = webdriver.Chrome(executable_path=driver_path)

Hata:

d:\Python\Yeni klasör\main.py:5: DeprecationWarning: executable_path has been deprecated, please pass in a Service object
  browser = webdriver.Chrome(executable_path=driver_path)
Traceback (most recent call last):
  File "d:\Python\Yeni klasör\main.py", line 5, in <module>
    browser = webdriver.Chrome(executable_path=driver_path)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Niuren\AppData\Roaming\Python\Python311\site-packages\selenium\webdriver\chrome\webdriver.py", line 81, in __init__
    super().__init__(
  File "C:\Users\Niuren\AppData\Roaming\Python\Python311\site-packages\selenium\webdriver\chromium\webdriver.py", line 106, in __init__
    super().__init__(
  File "C:\Users\Niuren\AppData\Roaming\Python\Python311\site-packages\selenium\webdriver\remote\webdriver.py", line 288, in __init__
    self.start_session(capabilities, browser_profile)
  File "C:\Users\Niuren\AppData\Roaming\Python\Python311\site-packages\selenium\webdriver\remote\webdriver.py", line 381, in start_session
    response = self.execute(Command.NEW_SESSION, parameters)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Niuren\AppData\Roaming\Python\Python311\site-packages\selenium\webdriver\remote\webdriver.py", line 444, in execute
    self.error_handler.check_response(response)
  File "C:\Users\Niuren\AppData\Roaming\Python\Python311\site-packages\selenium\webdriver\remote\errorhandler.py", line 249, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.SessionNotCreatedException: Message: session not created exception: Missing or invalid capabilities
  (Driver info: chromedriver=2.35.528161 (5b82f2d2aae0ca24b877009200ced9065a772e73),platform=Windows NT 10.0.22621 x86_64)
              

Şöyle deneyin:

from selenium.webdriver import Chrome
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options
options = Options()
options.binary_location = r"C:\Program Files\Google\Chrome\Application\chrome.exe"
service = Service(executable_path="./chromedriver.exe")
driver = Chrome(service=service, options=options)
              

Yine olmadı, aynı hatayı veriyor:

File "d:\Python\Yeni klasör\main.py", line 8, in <module>
    driver = Chrome(service=service, options=options)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Niuren\AppData\Roaming\Python\Python311\site-packages\selenium\webdriver\chrome\webdriver.py", line 81, in __init__
    super().__init__(
  File "C:\Users\Niuren\AppData\Roaming\Python\Python311\site-packages\selenium\webdriver\chromium\webdriver.py", line 106, in __init__
    super().__init__(
  File "C:\Users\Niuren\AppData\Roaming\Python\Python311\site-packages\selenium\webdriver\remote\webdriver.py", line 288, in __init__
    self.start_session(capabilities, browser_profile)
  File "C:\Users\Niuren\AppData\Roaming\Python\Python311\site-packages\selenium\webdriver\remote\webdriver.py", line 381, in start_session
    response = self.execute(Command.NEW_SESSION, parameters)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Niuren\AppData\Roaming\Python\Python311\site-packages\selenium\webdriver\remote\webdriver.py", line 444, in execute
    self.error_handler.check_response(response)
  File "C:\Users\Niuren\AppData\Roaming\Python\Python311\site-packages\selenium\webdriver\remote\errorhandler.py", line 249, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.SessionNotCreatedException: Message: session not created exception: Missing or invalid capabilities
  (Driver info: chromedriver=2.35.528161 (5b82f2d2aae0ca24b877009200ced9065a772e73),platform=Windows NT 10.0.22621 x86_64)

chrome driver klasörin içinde de var kodda yazan path’de de var.

Şu şekilde çözdüm. Selenium biraz değişmiş:

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
options = Options()
options.add_argument("start-maximized")
driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()), options=options)
driver.get("https://www.instagram.com")