[ปัญหา] การติดตั้ง selenium ไม่สามารถรันได้

ตอบกระทู้

รูปแสดงอารมณ์
:icon_plusone: :like: :plusone: :gfb: :-D :) :( :-o 8O :? 8) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :wink: :!: :?: :idea: :arrow: :| :mrgreen: :angry: :baa: :biggrin:
รูปแสดงอารมณ์อื่นๆ

BBCode เปิด
[img] เปิด
[url] เปิด
[Smile icon] เปิด

กระทู้แนะนำ
   

มุมมองที่ขยายได้ กระทู้แนะนำ: [ปัญหา] การติดตั้ง selenium ไม่สามารถรันได้

Re: [ปัญหา] การติดตั้ง selenium ไม่สามารถรันได้

โดย nuattawoot » 08/05/2018 1:36 pm

ติดตั้งแล้ว path จะอยู่ตามนี้
driver = webdriver.Chrome('/usr/local/lib/python2.7/site-packages/chromedriver')

Re: [ปัญหา] การติดตั้ง selenium ไม่สามารถรันได้

โดย rangsan » 08/05/2018 1:32 pm

nuattawoot เขียน:ลองกำหมด PATH ให้มันยัง Fix มันไว้เลย
ตัวอย่าง
# -*- coding: utf-8 -*-

from selenium import webdriver
import re
import re,unittest,time
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.keys import Keys

driver = webdriver.Chrome('/usr/local/lib/python2.7/site-packages/chromedriver')

driver.get("https://www.mindphp.com/forums/index.php")

ลองทำตามแต่ว่ายังขึ้น Path ไม่ถูกครับ

โค้ด: เลือกทั้งหมด

# -*- coding: utf-8 -*-

from selenium import webdriver
import re
import re,unittest,time
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.keys import Keys

driver = webdriver.Firefox('/usr/share/applications/Firefox Web Browser')

driver.get("https://www.mindphp.com")
ผลลัพธ์ Error Path ไม่ถูก

โค้ด: เลือกทั้งหมด

Traceback (most recent call last):
  File "/home/com003/PycharmProjects/m058/test.py", line 9, in <module>
    driver = webdriver.Firefox('usr/share/applications/Firefox Web Browser')
  File "/home/com003/PycharmProjects/m058/venv/lib/python3.6/site-packages/selenium/webdriver/firefox/webdriver.py", line 139, in __init__
    firefox_profile = FirefoxProfile(firefox_profile)
  File "/home/com003/PycharmProjects/m058/venv/lib/python3.6/site-packages/selenium/webdriver/firefox/firefox_profile.py", line 78, in __init__
    ignore=shutil.ignore_patterns("parent.lock", "lock", ".parentlock"))
  File "/usr/lib/python3.6/shutil.py", line 309, in copytree
    names = os.listdir(src)
FileNotFoundError: [Errno 2] No such file or directory: 'usr/share/applications/Firefox Web Browser'
ถาพประกอบ path
Path.png
Path.png (39.01 KiB) Viewed 996 times
ใช่ตรงนี้มั้ยครับ

Re: [ปัญหา] การติดตั้ง selenium ไม่สามารถรันได้

โดย nuattawoot » 08/05/2018 11:00 am

ลองกำหมด PATH ให้มันยัง Fix มันไว้เลย
ตัวอย่าง
# -*- coding: utf-8 -*-

from selenium import webdriver
import re
import re,unittest,time
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.keys import Keys

driver = webdriver.Chrome('/usr/local/lib/python2.7/site-packages/chromedriver')

driver.get("https://www.mindphp.com/forums/index.php")

[ปัญหา] การติดตั้ง selenium ไม่สามารถรันได้

โดย rangsan » 07/05/2018 6:49 pm

ขั้นตอนการติดตั้งผ่าน Terminal

โค้ด: เลือกทั้งหมด

sudo pip install selenium
ภาพประกอบ
install_selenium.png
install_selenium.png (9.36 KiB) Viewed 1017 times
ผลลัพธ์การรันโค้ด
output_install_selenium.png
output_install_selenium.png (48.89 KiB) Viewed 1017 times
เมื่อทำการรันโค้ดบน Pycharm

โค้ด: เลือกทั้งหมด

from selenium import webdriver

browser = webdriver.Firefox()

browser.get('https://www.mindphp.com')
ผลัพธ์ Error

โค้ด: เลือกทั้งหมด

Traceback (most recent call last):
  File "/home/com003/PycharmProjects/m058/venv/lib/python3.6/site-packages/selenium/webdriver/common/service.py", line 76, in start
    stdin=PIPE)
  File "/usr/lib/python3.6/subprocess.py", line 709, in __init__
    restore_signals, start_new_session)
  File "/usr/lib/python3.6/subprocess.py", line 1344, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'geckodriver': 'geckodriver'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/com003/PycharmProjects/m058/test.py", line 3, in <module>
    browser = webdriver.Firefox()
  File "/home/com003/PycharmProjects/m058/venv/lib/python3.6/site-packages/selenium/webdriver/firefox/webdriver.py", line 152, in __init__
    self.service.start()
  File "/home/com003/PycharmProjects/m058/venv/lib/python3.6/site-packages/selenium/webdriver/common/service.py", line 83, in start
    os.path.basename(self.path), self.start_error_message)
selenium.common.exceptions.WebDriverException: Message: 'geckodriver' executable needs to be in PATH.


ภาพประกอบ
Error_code.png
เหมือนโปรแกรมต้องการไฟล์ geckodriver หรือเปล่าครับ

ข้างบน