PYTHON reptile baidu beautiful pictures

from urllib import request
import re
import os
def main():
#page=request.urlopen("http://image.baidu.com/search/index?tn=baiduimage&ipn=r&ct=201326592&cl=2&lm=-1&st=-1&fr=&sf=1&fmq=1461834053046_R&pv=&ic=0&nc=1&z=&se=1&showtab=0&fb=0&width=&height=&face=0&istype=2&itg=0&ie=utf-8&word=%E5%A4%B4%E5%83%8F#z=0&pn=&ic=0&st=-1&face=0&s=0&lm=-1" )
# "https://image.baidu.com/search/index?tn=baiduimage&ipn=r&ct=201326592&cl=2&lm=-1&st=-1&fm=index&fr=&hs=0&xthttps=111111&sf=1&fmq=&pv=&ic=0&nc=1&z=&se=1&showtab=0&fb=0&width=&height=&face=0&istype=2&ie=utf-8&word=%E4%B8%AD%E5%9B%BD&oq=%E4%B8%AD%E5%9B%BD&rsp=-1")
page = request.urlopen("https://image.baidu.com/search/index?tn=baiduimage&ipn=r&ct=201326592&cl=2&lm=-1&st=-1&fm=index&fr=&hs=0&xthttps=111111&sf=1&fmq=&pv=&ic=0&nc=1&z=&se=1&showtab=0&fb=0&width=&height=&face=0&istype=2&ie=utf-8&word=%E7%BE%8E%E5%A5%B3&oq=%E7%BE%8E%E5%A5%B3&rsp=-1")
context=page.read().decode('utf-8')
pic=re.findall("https://.*?jpg",context)
count = 0; # 文件的起始名称为 0
for url in pic:
print(url)
bytes = request.urlopen(url);
if (url.find('.') != -1): # 2
name =url[url.find('.', len(url) - 5):];
f = open("D:/image/" + str(count) + name, 'wb'); # and open a file, ready to write binary file f.write (bytes.read ()); # the Write is not directly write data to a file, but the first written in a particular buffer memory f.flush (); # data is immediately written to the buffer the buffer and empty the buffer f.close (); # close the file COUNT + = . 1; IF the __name__ == '__main__': main ()





Guess you like

Origin www.cnblogs.com/tuozizhang/p/11086546.html