【发布时间】:2020-05-08 16:07:05
【问题描述】:
我想用 Python3 为 Instagram.com 创建一个自动登录。我告诉自己,我必须使用它来处理网站:
from selenium import webdriver
但在所有教程中,我发现他们对此没有任何问题,但我收到一条错误消息:
我浏览了其他问题,发现 this one 也应该可以解决我的问题,但是 Website 和他们提出的代码并没有解决我的问题。
到目前为止我的完整代码:
from selenium import webdriver
from time import sleep
username = "username"
class InstaBot:
def __init__(self):
self.driver = webdriver.Chrome()
driver.get("https://instagram.com")
sleep(2)
login_field = driver.find_element_by_xpath('/html/body/div[1]/section/main/article/div[2]/div[1]/div/form/div[2]/div/label/input').send_keys(username)
InstaBot()
我该如何解决这个问题?
编辑:我现在知道我必须先在命令提示符下使用该代码安装 Selenium:
pip3 install selenium
我做到了,并在 YouTube 上观看了 this Tutorial 并让它像他一样,但它就是行不通。 :(
它向控制台打印一条很长的错误消息:
Traceback (most recent call last):
File "C:\Users\Jonas\AppData\Local\Programs\Python\Python37-32\lib\site-
packages\selenium\webdriver\common\service.py", line 76, in start
stdin=PIPE)
File "C:\Users\Jonas\AppData\Local\Programs\Python\Python37-
32\lib\subprocess.py", line 775, in __init__
restore_signals, start_new_session)
File "C:\Users\Jonas\AppData\Local\Programs\Python\Python37-
32\lib\subprocess.py", line 1178, in _execute_child
startupinfo)
FileNotFoundError: [WinError 2] Das System kann die angegebene Datei nicht
finden
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "main.py", line 16, in <module>
InstaBot()
File "main.py", line 8, in __init__
self.driver = webdriver.Chrome()
File "C:\Users\Jonas\AppData\Local\Programs\Python\Python37-32\lib\site-
packages\selenium\webdriver\chrome\webdriver.py", line 73, in __init__
self.service.start()
File "C:\Users\Jonas\AppData\Local\Programs\Python\Python37-32\lib\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: 'chromedriver'
executable needs to be in PATH. Please see
https://sites.google.com/a/chromium.org/chromedriver/home
【问题讨论】:
标签: python python-3.x selenium authentication selenium-webdriver