I wish you a happy Tanabata
Sister figure
1 ImportRequests2 fromlxmlImportetree3 ImportOS4 defHeaders (referer):#The download of the picture may be related to the referer of the head, so the referer is set to a transform value to evade the anti-grilled5headers = {6 'user-agent':'mozilla/5.0 (Windows NT 10.0; WOW64) applewebkit/537.36 (khtml, like Gecko) chrome/68.0.3440.106 safari/537.36',7 'Referer':'{}'. Format (referer)}8 returnHeaders9 defTuji (PAG):#looking for a picture setTenFullUrl ='http://www.mzitu.com/page/{}/'. Format (PAG) Oneshouye_html =requests.get (FullUrl) AShouye_html_text =Shouye_html.text -Shouye_ele =etree. HTML (Shouye_html_text) -Tj_list = Shouye_ele.xpath ('//*[@id = "pins"]/li/a/@href')#find the map set URL for each page theTuji_url_list = [] - forTj_urlinchtj_list: - tuji_url_list.append (Tj_url) - returntuji_url_list + defGettuji_info (tj_url_list):#collection of URL lists to collect information about the atlas - forTj_url_1inchTj_url_list:#tj_url_1---> http://www.mzitu.com/146823 +tj_html = Requests.get (Tj_url_1, headers=headers (tj_url_1)) ATj_html_text =Tj_html.text atTj_ele =etree. HTML (Tj_html_text) -Img_title = Tj_ele.xpath ('//h2[@class = "Main-title"]/text ()') [0]#Atlas Name -max_pag_list = Int (Tj_ele.xpath ('/html/body/div[2]/div[1]/div[4]/a[5]/span/text ()') [0])#Find maximum pages - ifOs.path.exists (img_title) = =True: - Print('!') - Else: in Os.mkdir (img_title) - forIinchRange (1, int (max_pag_list + 1)): totj_url_2 = Tj_url_1 +'/'+STR (i)#tj_url_2---> http://www.mzitu.com/146823 + Pag +tj_html = Requests.get (tj_url_2, headers=headers (tj_url_1)) -Tj_html_text =Tj_html.text theTj_ele =etree. HTML (Tj_html_text) *Img_url = Tj_ele.xpath ('//div[@class = "Main-image"]/p/a/img/@src') [0]#find the URL of a picture from a different tj_url_2 $ Print('is downloading'+img_title+'Section'+str (i) +'Zhang')Panax NotoginsengWith open (img_title+'/'+str (i) +'. jpg',"wb+") as JPG: -Jpg.write (Requests.get (Img_url, headers=headers (tj_url_2)). Content) the + if __name__=='__main__': Apags = Int (input ('How many pages do you want to make?')) the forPaginchRange (1,pags+1): +Gettuji_info (Tuji (PAG))
Python Reptile Tanabata Benefits