Python implements the spider function to download Mobile Phone wallpapers in batches

Source: Internet
Author: User

I found some nice mobile phone wallpapers on Baidu Post Bar and wanted to download them for use. However, it was too troublesome to save them one by one, so I wrote a python program to crawl and download images in batches.

The http://tieba.baidu.com/p/1904141161 of the page to crawl? Pid = 24952618510 #24952618510

Program code:

#! /Usr/bin/env pythonimport reimport urllibdef getHtml (url): page = urllib. urlopen (url) html = page. read () return htmldef getImg (html): reg = r'src = "(. *? \. Jpg) "width 'imgre = re. compile (reg) imglist = re. findall (imgre, html) x = 0for imgre in imglist: urllib.urlretrieve(imgre,'{s.jpg '% x) x + = 1 html = getHtml ("http://tieba.baidu.com/p/1904141161? Pid = 24952618510 #24952618510 ") print getImg (html)

650) this. width = 650; "width =" 758 "height =" 505 "title =" pic.jpg "style =" width: 669px; height: 443px; "src =" http://www.bkjia.com/uploads/allimg/131228/1532555T9-0.jpg "/>

The download is successful. It's good to open a file. You have a good time!

This article is from the "Old Xu's Private food" blog and will not be reposted!

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.