无法从 xampp 命令行 运行 python 编程

Can't run python program from xampp command line

我在 python 中编写了一段代码,使用 selenium 从网站上抓取一些数据。当我在系统命令行中 运行 时,这段代码完全有效。但是当我从 xampp 命令行 运行 它给出错误并显示此消息

Traceback (most recent call last): File "C:\Users\Marajul\AppData\Local\Programs\Python\Python38-32\lib\site-packages\selenium\webdriver\common\service.py", line 72, in start self.process = subprocess.Popen(cmd, env=self.env, File "C:\Users\Marajul\AppData\Local\Programs\Python\Python38-32\lib\subprocess.py", line 854, in init self._execute_child(args, executable, preexec_fn, close_fds, File "C:\Users\Marajul\AppData\Local\Programs\Python\Python38-32\lib\subprocess.py", line 1307, in _execute_child hp, ht, pid, tid = _winapi.CreateProcess(executable, args, FileNotFoundError: [WinError 2] The system cannot find the file specified

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "C:\xampp\htdocs\Dairy\API\toph\python\a.py", line 16, in driver = Chrome(webdriver) File "C:\Users\Marajul\AppData\Local\Programs\Python\Python38-32\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 73, in init self.service.start() File "C:\Users\Marajul\AppData\Local\Programs\Python\Python38-32\lib\site-packages\selenium\webdriver\common\service.py", line 81, in start raise WebDriverException( selenium.common.exceptions.WebDriverException: Message: 'chromedriver3.exe' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home

from selenium.webdriver import Chrome
import pandas as pd
import mysql.connector

mydb = mysql.connector.connect(
  host="localhost",
  user="root",
  passwd="",
  database="dairy"
)

mycursor = mydb.cursor()

webdriver = 'chromedriver3.exe'

driver = Chrome(webdriver)
cnt=0

while 1:
    page_nb=(str)(cnt);
    url = "https://toph.co/submissions/filter?author=590d7d60de14194eb555201c&start="+page_nb+"&verdict="
    cnt=cnt+64
    driver.get(url)
    quotes = driver.find_elements_by_class_name("syncer")
    if(len(quotes)==0):
        break
    for quote in quotes:
        row=quote.find_elements_by_tag_name("td")
        link=row[2].find_elements_by_tag_name('a')
        time1=row[3].find_elements_by_class_name('timestamp')
        time=time1[0].get_attribute('data-time')
        urlp=""
        if(link):
            urlp=link[0].get_attribute('href')
        sql1="SELECT * FROM submission WHERE id=%s AND oj='toph'"
        val1 = (row[0].text,)
        mycursor.execute(sql1,val1)
        myresult = mycursor.fetchall()
        if(len(myresult)==0):
            sql="INSERT INTO submission (id,dt,link,name,ver,oj) VALUES (%s,%s,%s,%s,%s,'toph')"
            val=(row[0].text,time,urlp,row[2].text,row[7].text)
            mycursor.execute(sql, val)
            mydb.commit()

print("successfull")
driver.close()

我不是 python 方面的专家所以请帮我解决这个问题 :)

您的问题是常见的 "not in PATH" 类型的问题,错误消息清楚地指出:

Message: 'chromedriver3.exe' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home

解决方案是使用二进制文件的绝对路径(如果可以指定)或编辑全局环境 PATH 变量并将该二进制文件的位置添加到其中。

我遇到过类似的问题,看起来这个错误对 windows 来说是普遍的,在 subprocess.py 中设置 shell=True 后我能够解决它。