单独在命令行里运行没错,打包成exe后运行出错。
错误:
D:\1HelloWorld\PythonDeve\spider>D:\1HelloWorld\PythonDeve\spider\dist\baiduimg.
exe
Traceback (most recent call last):
File "baiduimg.py", line 68, in
dataList = getManyPages('缇庡コ',2)
File "baiduimg.py", line 46, in getManyPages
urls.append(requests.get(url,params=i).json().get('data'))
File "requests\api.pyc", line 72, in get
File "requests\api.pyc", line 58, in request
File "requests\sessions.pyc", line 508, in request
File "requests\sessions.pyc", line 618, in send
File "requests\adapters.pyc", line 407, in send
File "requests\adapters.pyc", line 226, in cert_verify
IOError: Could not find a suitable TLS CA certificate bundle, invalid path: D:\1
HelloWorld\PythonDeve\spider\dist\library.zip\certifi\cacert.pem
Python源码如下,求大佬回复
#coding=utf-8
import sys
reload(sys)
sys.setdefaultencoding('utf8')
import requests
import os
from time import ctime,sleep
def getManyPages(keyword,pages):
params=[]
for i in range(30,30*pages+30,30):
params.append({
'tn': 'resultjson_com',
'ipn': 'rj',
'ct': 201326592,
'is': '',
'fp': 'result',
'queryWord': keyword,
'cl': 2,
'lm': -1,
'ie': 'utf-8',
'oe': 'utf-8',
'adpicid': '',
'st': -1,
'z': '',
'ic': 0,
'word': keyword,
's': '',
'se': '',
'tab': '',
'width': '',
'height': '',
'face': 0,
'istype': 2,
'qc': '',
'nc': 1,
'fr': '',
'pn': i,
'rn': 30,
'gsm': '1e',
'1488942260214': ''
})
url = 'https://image.baidu.com/search/acjson'
urls = []
for i in params:
urls.append(requests.get(url,params=i).json().get('data'))
return urls
def getImg(dataList, localPath):
if not os.path.exists(localPath): # 新建文件夹
os.mkdir(localPath)
x = 0
for list in dataList:
for i in list:
if i.get('thumbURL') != None:
print('正在下载:%s' % i.get('thumbURL'))
ir = requests.get(i.get('thumbURL'))
open(localPath + '%d.jpg' % x, 'wb').write(ir.content)
x += 1
else:
print('图片链接不存在')
if name == '__main__':
dataList = getManyPages('美女',2)
# 参数1:关键字,参数2:要下载的页数
getImg(dataList,"D:\Uarebeautiful\")
# 参数2:指定保存的路径