Python 3.4 cx_freeze [WinError 5] 使用 Selenium - 仅在其他机器上

Python 3.4 cx_freeze [WinError 5] using Selenium - Only on other machines

我最近开始研究 cx_freeze 并创建 .exe 文件供其他人使用。

脚本相当简单:它使用 Selenium 抓取网站上的 javascript 敏感内容,并在找到匹配的 href 时通知用户 + 将 link 复制到剪贴板:

main.py中的主要代码:

from bs4 import BeautifulSoup
from selenium import webdriver
import time
import pyperclip

def check():
    browser.get(browser.current_url)
    page_html = browser.page_source.encode('utf8')
    soup = BeautifulSoup(page_html, "lxml")
    complete_list = soup.find_all('a', href=True)

    for a in complete_list:
        if LINK_TO_FIND in a['href']:
            pyperclip.copy(a['href'])
            while True:
                beep()

browser = webdriver.Chrome(executable_path=path_to_chromedriver)
browser.get(URL_TO_CHECK)

while True:

    check()
    time.sleep(5)

setup.py中的cx_freeze代码:

import sys
from cx_Freeze import setup, Executable

build_exe_options = {"packages": ["os", "lxml", "gzip"], "excludes": ["tkinter"]}

base = 'Console'

setup(  name = "web_scraper",
    version = "0.1",
    description = "desc",
    options = {"build_exe": build_exe_options},
    executables = [Executable("main.py", base=base)])

直到昨天,这个脚本 运行 在我的和其他机器上都没有问题。但是从昨天开始,每当其他人运行新建的 .exe:s 时,这个错误就开始弹出。 (新的对我来说仍然可以正常工作,旧的版本在其他机器上仍然可以工作):

Traceback (most recent call last):
    File "C:\Python34\lib\site-packages\selenium\webdriver\chrome\service.py", line 68, in start
    File "C:\Python34\lib\subprocess.py", line 859, in __init__
    File "C:\Python34\lib\subprocess.py", line 1112, in _execute_child
PermissionError: [WinError 5] Access is denied

During handling of the above exception, another exception occured:

Traceback (most recent call last):
    File "C:\Python34\lib\site-packages\cx_Freeze\initscripts\Console.py", line 27, in (module)
    File "main.py", line 48, in (module)
    File "C:\Python34\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 62, in __init__
    File "C:\Python34\lib\site-packages\selenium\webdriver\chrome\service.py", line 80, in start
selenium.common.exceptions.WebDriverException: Message: 'exe.win32-3.4' executable may have wrong permissions. Please see https://sites.google.com/a/chromium.org/chromedriver/home

我尝试过的一些事情:

好吧,经过大约 4 小时的故障排除后,我意识到 path_to_chromedriver 在我发送的版本末尾丢失了 \chromedriver.exe,但对于我使用的版本来说是正确的本地。拍我。