Python code example using regular expressions to capture web page images

Y2J
Release: 2017-05-03 16:15:33
Original
1332 people have browsed it

This article mainly introduces the method of Python using regular expressions to capture web page images. It analyzes the reading of Python web page files and the related operation skills of regular matching based on specific examples. Friends in need can refer to the following

The example in this article describes how Python uses regular expressions to capture web page images. Share it with everyone for your reference, the details are as follows:

#!/usr/bin/python
import re
import urllib
#获取网页信息
def getHtml(url):
  page = urllib.urlopen(url)
  html = page.read()
  return html
def getImg(html):
#匹配网页中的图片
 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=360tpdq")
print getImg(html)
Copy after login

The above is the detailed content of Python code example using regular expressions to capture web page images. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!