Python 2.7_ Crawl Sister map website single page test picture _20170114

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.