Python crawls images of a webpage-for example, Baidu Post
Python crawls images of a webpage-for example, Baidu Post
Author: vpoet
Date: about winter
Note: Do not tell me if you want to copy it at will.
# Coding: utf-8import urllibimport urllib2import reif _ name _ = "_ main _": rex = r 'src = "(http://imgsrc.baidu.com/forum/ww.3d580 .*? \. Jpg) "'; Response = urllib2.urlopen (" http://tieba.baidu.com/p/3842835603? Fr = fr "); Html = Response. read (); lists = re. findall (rex, Html); x = 0; for picurl in lists: urllib. urlretrieve (picurl, 'c: \ Users \ Administrator \ Desktop \ pic \ %s.jpg '% x); x = x + 1; print picurl; print 'downloadpicover' # image storage path: c: \ Users \ Administrator \ Desktop \ pic # test crawling URL: http://tieba.baidu.com/p/3842835603? Fr = fr
Run:
Because the image is downloaded one by one, it may be a little slow. If multiple threads are used later, download zookeeper.