Python code instance for capturing web images using regular expressions

Source: Internet
Author: User
This article mainly introduces Python's method of capturing webpage images using regular expressions, and analyzes the reading and regular expression matching related operations of Python webpage files based on specific examples, for more information about how to capture web images using regular expressions in Python, refer to the following article. This article analyzes the reading and regular expression matching operations of Python Web files based on specific examples, for more information, see

This example describes how Python uses regular expressions to capture web images. We will share this with you for your reference. The details are as follows:

#! /Usr/bin/pythonimport reimport urllib # obtain webpage information def getHtml (url): page = urllib. urlopen (url) html = page. read () return htmldef getImg (html): # match the image reg = r'src = "(. *? \. Jpg) "alt 'imgre = re. compile (reg) imglist = re. findall (imgre, html) x = 0 for imgurl in imglist: urllib.urlretrieve(imgurl,'{s.jpg '% x) x + = 1 html = getHtml ("http://photo.bitauto.com /? WT. mc_id = 360 tpdq ") print getImg (html)

The above is the details of the Python code instance that uses regular expressions to capture web images. For more information, see other related articles in the first PHP community!

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.