widows下python脚本生成exe批量检测网站

@高效码农  December 10, 2019

整体思路:
python脚本检测网址是否可以打开,TDK是否被篡改(待实现);将python脚本打包成exe

一、python脚本

新建脚本DetectUrl.py

import urllib.request
import time
import datetime

opener = urllib.request.build_opener()
opener.addheaders = [('User-agent', 'Mozilla/49.0.2')]
# 这个是你放网址的文件名,改过来就可以了
file = open('test.txt')
lines = file.readlines()
aa = []
for line in lines:
    temp = line.replace('\n', '')
    aa.append(temp)
print(aa)

print('开始检查:')
for a in aa:
    tempUrl = a
    try:
        opener.open(tempUrl)
        print(tempUrl+'没问题')
    except urllib.error.HTTPError:
        print(tempUrl+'=访问页面出错')
        with open('检测结果.txt', 'a') as f:
            f.write('\n')
            f.write('访问页面出错%s:%s' % (datetime.datetime.now().strftime('%Y-%m-%d'), tempUrl))
    except urllib.error.URLError:
        print(tempUrl+'=访问页面出错')
        with open('检测结果.txt', 'a') as f:
            f.write('\n')
            f.write('访问页面出错%s:%s' % (datetime.datetime.now().strftime('%Y-%m-%d'), tempUrl))
    time.sleep(0.1)

二、安装pyinstaller

pip install pyinstaller

检测是否安装成功:

pyinstaller --version
pyinstaller -v
(pandas-example) F:\python_workspace\pandas-example>pyinstaller -v
3.5

三、打包exe

pyinstaller -F -i favicon.ico DetectUrl.py


添加新评论