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!