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

yipeiwu_com6年前Python基础
复制代码 代码如下:

# -*- 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)

相关文章

python 接口测试response返回数据对比的方法

背景:之前写的接口测试一直没有支持无限嵌套对比key,上次testerhome逛论坛,有人分享了他的框架,看了一下,有些地方不合适我这边自己修改了一下,部署在jenkins上跑完效果还不...

Matplotlib中文乱码的3种解决方案

前言 Matplotlib是一个Python 2D绘图库,它可以在各种平台上以各种硬拷贝格式和交互式环境生成出具有出版品质的图形。 Matplotlib可用于Python脚本,Pytho...

Python3.6+selenium2.53.6自动化测试_读取excel文件的方法

Python3.6+selenium2.53.6自动化测试_读取excel文件的方法

环境: 编辑工具: 浏览器: 安装xlrd 安装DDT 一 分析 1 目录结构 2 导入包 二 代码 import xlrd cla...

pandas 数据归一化以及行删除例程的方法

如下所示: #coding:utf8 import pandas as pd import numpy as np from pandas import Series,DataFra...

python实发邮件实例详解

yagmail 实现发邮件 yagmail 可以更简单的来实现自动发邮件功能。 1、安装 pip install yagmail 2、简单举例 import yagmail...