我最近开始研究 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 位于正确的位置(如果不正确,则会引发另一个错误)。
最佳答案
好吧,经过大约 4 小时的故障排除后,我意识到 path_to_chromedriver
在我发送的版本末尾缺少 \chromedriver.exe
,但是适合我在本地使用的版本。向我开枪。
关于Python 3.4 cx_freeze [WinError 5] 使用 Selenium - 仅在其他机器上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31829300/