【发布时间】:2015-08-05 10:03:32
【问题描述】:
我最近开始研究 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 位于正确的位置(如果没有,则会引发另一个错误)。
【问题讨论】:
标签: python selenium python-3.4 cx-freeze