python抓取网页中的图片示例

yipeiwu_com6年前Python爬虫

复制代码 代码如下:

#coding:utf8
import re
import urllib
def getHTML(url):
    page = urllib.urlopen(url)
    html = page.read()
    return html

def getImg(html,imgType):
    reg = r'src="(.*?\.+'+imgType+'!slider)" '
    imgre = re.compile(reg)
    imgList = re.findall(imgre, html)
    x=0
    for imgurl in imgList:
        print imgurl
        urllib.urlretrieve(imgurl, '%s.%s' % (x, imgType))
        x =x+1


html= getHTML("//www.jb51.net")

getImg(html,'jpg')

相关文章

Python常用爬虫代码总结方便查询

beautifulsoup解析页面 from bs4 import BeautifulSoup soup = BeautifulSoup(htmltxt, "lxml") # 三种装...

Python爬虫实例扒取2345天气预报

Python爬虫实例扒取2345天气预报

寒假里学习了一下Python爬虫,使用最简单的方法扒取需要的天气数据,对,没听错,最简单的方法。甚至没有一个函数封装。。 网址:http://tianqi.2345.com/wea_hi...

python 爬取马蜂窝景点翻页文字评论的实现

python 爬取马蜂窝景点翻页文字评论的实现

使用Chrome、python3.7、requests库和VSCode进行爬取马蜂窝黄鹤楼的文字评论(http://www.mafengwo.cn/poi/5426285.html)。...

Python3实现爬取指定百度贴吧页面并保存页面数据生成本地文档的方法

分享给大家供大家参考,具体如下:Python3实现爬取指定百度贴吧页面并保存页面数据生成本地文档的方法。分享给大家供大家参考,具体如下: 首先我们创建一个python文件, tieba....

selenium+PhantomJS爬取豆瓣读书

本文实例为大家分享了selenium+PhantomJS爬取豆瓣读书的具体代码,供大家参考,具体内容如下 获取关于Python的全部书籍信息; 通过代码测试 request携带‘User...