Import re import urllib.request def open_url (URL): req = urllib.request.Request (URL) req.add_header (' User-agent ' , ' mozilla/5.0 (Windows NT 6.1;
WOW64) applewebkit/537.36 (khtml, like Gecko) chrome/45.0.2454.101 safari/537.36 ') page = Urllib.request.urlopen (req) html = Page.read (). Decode (' Utf-8 ') return HTML def get_img (HTML): # # #搜索图片地址 p = R ' \[(. +)] ' Imglist=re.findall (p,html ) return imglist[0] if __name__ = = ' __main__ ': firsturl = ' Http://jandan.net/ooxx ' nowYe = Int (Get_ye (Open_url (Firsturl))) print (' current page:%d '%nowye) while true:ywant = Int (input (' Please enter the page you want to download
Number: ')) if Ywant<=nowye and ywant >0:for i in Range (ywant): Print
url = ' http://jandan.net/ooxx/page-' +str (nowye-i) + ' #comments ' get_img (open_url (URL)) break Else:print (' Please re-enter pages: Range in '%d,0 ') '%nowye