Crawling Web Images Using python

Source: Internet
Author: User

Crawling Web Images Using python

Import reimport stringimport sysimport osimport urlliburl = "http://tieba.baidu.com/p/2521298181" # This is a post address imgcontent = urllib. urlopen (url ). read () # capture webpage content reg = r'src = "(. +? \. Jpg) "pic_ext 'imgre = re. compile (reg) urllist = imgre. findall (imgcontent) # urllist = re. findall (r 'src =" (http. +? \. Jpg) "', imgcontent, re. i) # extract the image link if not urllist: print 'not found... 'else: # download the image and save it to the pythonimg folder in the current directory. filepath = OS. getcwd () + '\ pythonimg' if OS. path. exists (filepath) is False: OS. mkdir (filepath) x = 1 print U' crawler ready... 'for imgurl in urllist: temp = filepath +' \ developers.jpg '% xprint U' is downloading the % s image' % xprint imgurlurllib. urlretrieve (imgurl, temp) x + = 1 print U' after the image is downloaded, the SAVE path is '+ filepath

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.