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!