Python tips for grabbing pictures of beautiful women

  • 2020-04-02 13:44:49
  • OfStack

Urllib2 module and regular expression module are used. Now directly on the code:

[/ code]
#! The/usr/bin/env python
# - * - coding: utf-8 - * -
Download network content through the urllib(2) module
The import urllib, urllib2, gevent
Introduce regular expression module, time module
The import re, time
The from gevent import monkey

Monkey. Patch_all ()

Def geturllist (url) :
      Url_list = []
      Print the url            
      S = urllib2. Urlopen (url)
      Text = s.r ead ()
      # regular match, match the picture in it
      HTML = re search (r ' < Ol. * < / ol > ', the text, re S)
      Urls = re. Finditer (r ' < p > < Img SRC = "(. +?) JPG "/ > < / p > ', HTML. Group (), re. I)
      For I in urls:
              Url = i.g roup (1). Strip () + STR (" JPG ")
              Url_list. Append (url)
      Return url_list

Def the download (down_url) :
      Name = STR (time. Time ()) [: - 3] + "_" + re. Sub ('. +? / ', ' ', down_url)
      Print the name
      Urllib. Urlretrieve (down_url, "D: \ \ TEMP \ \" + name)

Def getpageurl () :
      Page_list = []
      Loop through the list page
      For the page in the range (1700) :
              Url = "http://jandan.net/ooxx/page-" + STR (page) + "# comments"
              Add the generated url to the page_list
              Page_list. Append (url)
      Print page_list
      Return page_list
If __name__ = = "__main__" :
      The jobs = []
      Pageurl = getpageurl () [: : 1]
      Download pictures
      For I in pageurl:
              For (downurl) geturllist in (I) :
                      Jobs. Append (gevent. Spawn (download, downurl))
      Gevent. Joinall (jobs)
[/ code]

The program is not long only 45 lines, not too difficult, you can study, here I just throw out a brick to attract jade, you can develop other grab procedures according to the principle, ha ha, want to go... I won't say more ~~


Related articles: