屹洋屹可  

#!/1111111111usr/bin/env python
# -*- encoding: utf-8 -*-
# Created on 2018-11-15 15:24:12
# Project: dcsconvert

import json
import requests
import urllib
from bs4 import BeautifulSoup
from requests.packages.urllib3.exceptions import InsecureRequestWarning
import getproxyinfo
import urllib.parse
from requests.packages.urllib3.exceptions import InsecureRequestWarning

requests.packages.urllib3.disable_warnings(InsecureRequestWarning)

fp = open("./mingxing.txt", 'a')
for line in range(129,2000):

url ="https://sp0.baidu.com/8aQDcjqpAAV3otqbppnN2DJv/api.php?resource_id=28266&from_mid=1&&format=json&ie=utf-8&oe=utf-8&query=%E6%98%8E%E6%98%9F&sort_key=&sort_type=1&stat0=&stat1=&stat2=&stat3=&pn="+str(line*100)+"&rn=100&cb=jQuery110208427746793656827_1542333834490&_=1542333834575"
print(url)
r = requests.get(url)
r.encoding = 'utf-8'
txt_res =r.text[r.text.find("(")+1:]
txt_res = txt_res[:-1]
hjson = json.loads(txt_res)

if ("data" not in hjson):
pass

for tmp in hjson['data']:
if ("result" in tmp):
for tmp2 in tmp['result']:
ename =""
pic =""
if ("ename" in tmp2):
print("ename:" + tmp2['ename'])
ename =tmp2['ename']

if ("ename" in tmp2):
print("pic_4n_78:" + tmp2['pic_4n_78'].replace("\\/","/"))
pic =tmp2['pic_4n_78'].replace("\\/","/")

content =ename + "\t" + pic
content =content.replace("\n","")
fp.write(content+"\n")
fp.flush()

fp.close()

# num =0
# fold=2
# for line in open("D:\\images\\1116.txt", encoding='UTF-8'):
# num +=1
# line =line.replace("\n","")
# filename =line.split('\t')[0]#.decode('utf-8').encode('gbk')
# img_url =line.split('\t')[1]
# #img_url ="https://ss0.baidu.com/6ONWsjip0QIZ8tyhnq/it/u=1006387812,1107224606&fm=58&s=EFE6A5572D33439462EC58FE0300E070"
# folder ="D:\\images\\"+str(fold)+"\\"
# if num%6000 ==0:
# fold +=1
# folder = "D:\\images\\" + str(fold) + "\\"
#
# urllib.request.urlretrieve(img_url,folder + filename+".jpg")

posted on 2018-11-16 11:17  屹洋屹可  阅读(420)  评论(0)    收藏  举报