首先,我是编程的新手,python,这个论坛很抱歉有任何错误。
我写了一个 python 脚本,但希望能够在没有安装 python 的计算机上运行它,所以我做了一些研究,发现我需要下载一个程序才能将 py 转换为 exe。cx_freeze 是唯一支持 python 3.4 的。
我按照流行的 YouTube 视频 ( https://www.youtube.com/watch?v=XHcDHSWRCRQ ) 中的说明进行操作,但是当我双击 exe 时,命令框会弹出一瞬间然后关闭。有一些文字,但它对我来说太快了阅读它。
看起来这些线程是关于同一个问题,但他们没有得到答复。有任何想法吗?
谢谢!
编辑:如果有帮助,这是我的 setup.py
from cx_Freeze import setup, Executable
setup(
name = "Teacher Pages Search" ,
version = "1" ,
description = "By Gambiteer" , executables = [Executable("Teacher Pages Search.py")] ,
)
这是教师页面 Search.py
import urllib.request
import html.parser
import webbrowser
class MyHTMLParser(html.parser.HTMLParser):
def __init__(self):
super().__init__(False)
self.teacherLink = False
self.url = ""
def handle_starttag(self, tag, attrs):
if tag == 'a':
for combo in attrs:
if "sw-directory-item" in combo[1]:
self.teacherLink = True
if self.teacherLink is True:
if "http:" in combo[1]:
self.url = combo[1]
def handle_data(self, data):
data = data.lower()
data = data.replace("'","")
data = data.replace("\\","")
data = data.replace(" ","")
if self.teacherLink is True:
for teacher in teacherList:
if teacher in data:
webbrowser.open(self.url)
self.teacherLink = False
teacherListInput = input("Enter the last name of your teachers, without punctuation, separated by commas:\n")
teacherListInput = teacherListInput.replace(" ","")
teacherList = list()
while teacherListInput.find(',') != -1:
commaLoc = teacherListInput.find(',')
teacherName = teacherListInput[0:commaLoc]
teacherList.append(teacherName)
teacherListInput = teacherListInput[commaLoc+1:]
teacherList.append(teacherListInput)
f = urllib.request.urlopen("http://www.scarsdaleschools.k12.ny.us/site/Default.aspx?PageType=1&SiteID=65&ChannelID=94&DirectoryType=6")
webpage = f.read()
parser = MyHTMLParser()
html_parser = html.parser.HTMLParser()
unescaped = html_parser.unescape(str(webpage))
parser.feed(unescaped)
input("Press enter to exit")