1, url= http://www.mzitu.com/74100/x,2 value of 1 to 23
2, use the module OS to create files directory; Re module regular matching directory name picture; The time module restricts download times; Requests module gets the Web page source code; Urllib module urllib.urlretrieve (image URL, filename saved with extension x.jpg) method download picture
3. Knowledge Point file directory handler function encapsulates calling global variable
4. Code
#coding: Utf-8import osimport reimport requests as Rqimport urllibimport time# Create directory function save file location def create_catename (): # Remove the top directory name of the Web page url=urls[0] html=rq.get (URL). Text Cate_name=re.findall (R ' <a href= "http:/ Www.mzitu.com/xinggan "rel=" category tag > (. *?) </a> ', HTML] [0] path= ' d:\\%s '% cate_name return path# download picture definition n a global variable with n count as the file name of the picture n.jpg define n full variable In case of a for loop, the value of the last loop n is re-assigned def getimg (): global n n=1 for URL in URLs : html = rq.get (URL). text regex = Re.compile (' Python 2.7_ Crawl Sister map website single page test picture _20170114