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

时间:2015-08-05 10:03:33

标签: python selenium python-3.4 cx-freeze

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

脚本非常简单:它使用Selenium来抓取网站上对javascript敏感的内容,并在找到匹配的href +给链接到剪贴板的链接时向用户发出通知:

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

我尝试过的一些事情:

  • 编译旧版本只是为了检查是否有错误 用代码。
  • 执行python setup.py build
  • 时,以管理员身份启动控制台
  • 禁用我的防病毒软件
  • 确保chromedriver.exe位于正确的位置(如果没有,则会引发其他错误)。

1 个答案:

答案 0 :(得分:4)

好吧,经过大约4个小时的故障排除后,我意识到path_to_chromedriver在我发送的版本的最后缺少\chromedriver.exe,但对于我在本地使用的版本是正确的。拍我。