Home > Backend Development > Python Tutorial > 下载给定网页上图片的方法

下载给定网页上图片的方法

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-16 08:45:08
Original
1049 people have browsed it
复制代码 代码如下:

# -*- coding: utf-8 -*-
import re
import urllib
def getHtml(url):
#找出给出网页的源码
page = urllib.urlopen(url)
html = page.read()
return html

def getImg(html):
#正则
reg = r'src="(.*?\.jpg)"'
#编译正则
imgre = re.compile(reg)
#找出图片地址
imglist = re.findall(imgre,html)
#循环遍历
x = 0
for i in imglist:
urllib.urlretrieve(i,'%s.jpg' % x)
x+=1
html = getHtml(r'http://www.renren.com/')
getImg(html)
Related labels:
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