Python crawls images of a webpage-for example, Baidu Post

Source: Internet
Author: User

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.

 

 

 

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.