我最近开始研究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
好了,因此,在经过大约4个小时的故障排除后,我意识到我发送过来的版本在末尾path_to_chromedriver
丢失\chromedriver.exe
了,但是对于我在本地使用的版本是正确的。射死我
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句