iT邦幫忙

0

Python 這是怎麼回事 TypeError

  • 分享至 

  • xImage

第二行哪裡有錯

driver=webdriver.chrome("desktop\chromedriver")

程式碼

from selenium import webdriver
driver=webdriver.chrome("desktop\chromedriver")
drvier.get("http://www.google.com")
dlement=driver.find_element_by_class_name("gLFyf.gsfi")
element.send_keys("Selenium Python")

錯誤訊息

Traceback (most recent call last):
  File "D:\python\find.py", line 2, in <module>    
    driver=webdriver.chrome("desktop\chromedriver")
TypeError: 'module' object is not callable

https://ithelp.ithome.com.tw/upload/images/20210426/20119742eal377rSRJ.png

https://ithelp.ithome.com.tw/upload/images/20210426/20119742IG2jTnedYH.png

圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中
0
不明
driver = webdriver.Chrome('desktop\chromedriver')

Chrome C沒大寫call到其他東西

沒錯的話回應一下,你好像問兩次都沒人看出來蠻慘的。

看更多先前的回應...收起先前的回應...
kevin543 iT邦新手 5 級 ‧ 2021-04-26 22:06:16 檢舉

大寫還是一樣
https://ithelp.ithome.com.tw/upload/images/20210426/20119742g3FZ2yiLEA.png

不明 檢舉

不是這一個C 前一個
webdriver.Chrome 的 C
你改到後面 chromedriver 的 C 去了

kevin543 iT邦新手 5 級 ‧ 2021-04-26 22:13:27 檢舉
D:\python>python find.py
Traceback (most recent call last):
  File "C:\Users\Kevin\AppData\Local\Programs\Python\Python39\lib\site-packages\
selenium\webdriver\common\service.py", line 72, in start
    self.process = subprocess.Popen(cmd, env=self.env,
  File "C:\Users\Kevin\AppData\Local\Programs\Python\Python39\lib\subprocess.py"
, line 951, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "C:\Users\Kevin\AppData\Local\Programs\Python\Python39\lib\subprocess.py"
, line 1420, in _execute_child
    hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
FileNotFoundError: [WinError 2] 系統找不到指定的檔案。

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "D:\python\find.py", line 2, in <module>
    driver=webdriver.Chrome("desktop\chromedriver")
  File "C:\Users\Kevin\AppData\Local\Programs\Python\Python39\lib\site-packages\
selenium\webdriver\chrome\webdriver.py", line 73, in __init__
    self.service.start()
  File "C:\Users\Kevin\AppData\Local\Programs\Python\Python39\lib\site-packages\
selenium\webdriver\common\service.py", line 81, in start
    raise WebDriverException(
selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executabl
e needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chrome
driver/home
kevin543 iT邦新手 5 級 ‧ 2021-04-26 22:14:42 檢舉

執行寫一大堆 , 看不出來

不明 檢舉
driver = webdriver.Chrome('C:\Users\Kevin\OneDrive\Desktop\chromedriver')

改成絕對路徑?
看起來是沒抓到你桌面的那個chromedriver.exe

kevin543 iT邦新手 5 級 ‧ 2021-04-26 22:36:46 檢舉

D:\python>python find.py
File "D:\python\find.py", line 2
driver=webdriver.Chrome('C:\Users\Kevin\OneDrive\Desktop\chromedriver')
^
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in positio
n 2-3: truncated \UXXXXXXXX escape

kevin543 iT邦新手 5 級 ‧ 2021-04-26 22:37:02 檢舉
D:\python>python find.py
  File "D:\python\find.py", line 2
    driver=webdriver.Chrome('C:\Users\Kevin\OneDrive\Desktop\chromedriver')
                                                                          ^     
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in positio
n 2-3: truncated \UXXXXXXXX escape
不明 檢舉
driver = webdriver.Chrome('C:\\Users\\Kevin\\OneDrive\\Desktop\\chromedriver')

driver = webdriver.Chrome(r"C:\Users\Kevin\OneDrive\Desktop\chromedriver")
kevin543 iT邦新手 5 級 ‧ 2021-04-26 22:54:47 檢舉
D:\python>python find.py
Traceback (most recent call last):
  File "C:\Users\Kevin\AppData\Local\Programs\Python\Python39\lib\site-packages\
selenium\webdriver\common\service.py", line 72, in start
    self.process = subprocess.Popen(cmd, env=self.env,
  File "C:\Users\Kevin\AppData\Local\Programs\Python\Python39\lib\subprocess.py"
, line 951, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "C:\Users\Kevin\AppData\Local\Programs\Python\Python39\lib\subprocess.py"
, line 1420, in _execute_child
    hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
FileNotFoundError: [WinError 2] 系統找不到指定的檔案。

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "D:\python\find.py", line 2, in <module>
    driver = webdriver.Chrome('C:\\Users\\Kevin\\OneDrive\\Desktop\\chromedriver
')
  File "C:\Users\Kevin\AppData\Local\Programs\Python\Python39\lib\site-packages\
selenium\webdriver\chrome\webdriver.py", line 73, in __init__
    self.service.start()
  File "C:\Users\Kevin\AppData\Local\Programs\Python\Python39\lib\site-packages\
selenium\webdriver\common\service.py", line 81, in start
    raise WebDriverException(
selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executabl
e needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chrome
driver/home


D:\python>python find.py
Traceback (most recent call last):
  File "C:\Users\Kevin\AppData\Local\Programs\Python\Python39\lib\site-packages\
selenium\webdriver\common\service.py", line 72, in start
    self.process = subprocess.Popen(cmd, env=self.env,
  File "C:\Users\Kevin\AppData\Local\Programs\Python\Python39\lib\subprocess.py"
, line 951, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "C:\Users\Kevin\AppData\Local\Programs\Python\Python39\lib\subprocess.py"
, line 1420, in _execute_child
    hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
FileNotFoundError: [WinError 2] 系統找不到指定的檔案。

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "D:\python\find.py", line 2, in <module>
    driver = webdriver.Chrome(r"C:\Users\Kevin\OneDrive\Desktop\chromedriver")  
  File "C:\Users\Kevin\AppData\Local\Programs\Python\Python39\lib\site-packages\
selenium\webdriver\chrome\webdriver.py", line 73, in __init__
    self.service.start()
  File "C:\Users\Kevin\AppData\Local\Programs\Python\Python39\lib\site-packages\
selenium\webdriver\common\service.py", line 81, in start
    raise WebDriverException(
selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executabl
e needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chrome
driver/home

不明 檢舉
driver = webdriver.Chrome(r"C:\Users\Kevin\OneDrive\Desktop\chromedriver.exe")
kevin543 iT邦新手 5 級 ‧ 2021-04-27 09:54:41 檢舉
from selenium import webdriver
driver = webdriver.Chrome(r"C:\Users\Kevin\OneDrive\Desktop\chromedriver.exe")
drvier.get("http://www.google.com")
dlement=driver.find_element_by_class_name("gLFyf.gsfi")
element.send_keys("Selenium Python")
D:\python>python find.py
Traceback (most recent call last):
  File "C:\Users\Kevin\AppData\Local\Progrpy", line 72, in start
    self.process = subprocess.Popen(cmd, e
  File "C:\Users\Kevin\AppData\Local\Progr
    self._execute_child(args, executable, 
  File "C:\Users\Kevin\AppData\Local\Progr
    hp, ht, pid, tid = _winapi.CreateProce
FileNotFoundError: [WinError 2] 系統找不到

During handling of the above exception, an

Traceback (most recent call last):
  File "D:\python\find.py", line 2, in <mo
rograms\Python\Python39\lib\site-packages\selenium\webdriver\common\service.py", line 81, in start
    raise WebDriverException(
selenium.common.exceptions.WebDriverException: Message: 'chromedriver.exe' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home
kevin543 iT邦新手 5 級 ‧ 2021-04-27 23:01:40 檢舉

謝謝 ! 我改到
driver =webdriver.Chrome("D:\python\chromedriver.exe")
就可以執行了 , 但出現 Chrome正在受到自動軟體的控制

0
Wayne
iT邦新手 2 級 ‧ 2021-04-27 02:14:57

你試試看把chromedrive.exe放到這個project路徑底下
然後driver的路徑改這樣,試試看
driver = webdriver.Chrome()

kevin543 iT邦新手 5 級 ‧ 2021-04-27 09:55:36 檢舉

是貼到上面那樣嗎 ?

kevin543 iT邦新手 5 級 ‧ 2021-04-27 23:02:42 檢舉

謝謝 ! 我改到
driver =webdriver.Chrome("D:\python\chromedriver.exe")
就可以執行了 , 但出現 Chrome正在受到自動軟體的控制
我找網路 https://kknews.cc/zh-tw/code/3bqpyyy.html
還是無法解決

Wayne iT邦新手 2 級 ‧ 2021-04-28 00:57:51 檢舉

Chrome正在受到自動軟體的控制,應該是正確的
我跑的時候chrome上面也會出現這個提示,我看youtube上的教學也都有這個提示
https://youtu.be/nCYvlciLyiM?t=163
https://youtu.be/WnWQgUerR0c?t=442

0
huahualiu
iT邦新手 2 級 ‧ 2021-04-27 13:37:59

我自己在寫的時候是這樣寫:

driver = webdriver.Chrome(executable_path=PATH, options=options)
driver.get(web_url)

給你參考
可能你直接寫路徑,沒指定是給哪個參數(executable_path),導致出錯?

kevin543 iT邦新手 5 級 ‧ 2021-04-27 23:03:04 檢舉

謝謝 ! 我改到
driver =webdriver.Chrome("D:\python\chromedriver.exe")
就可以執行了 , 但出現 Chrome正在受到自動軟體的控制
我找網路 https://kknews.cc/zh-tw/code/3bqpyyy.html
還是無法解決

我要發表回答

立即登入回答