python爬虫 之 抓取高清图片

本文介绍了一个针对壁纸网站http://www.hbc333.com/的爬虫脚本实现过程,该脚本能够批量下载指定分辨率的图片。通过分析网页结构,使用Python的urllib和re模块抓取图片链接,并实现了多页图片的连续下载。
摘要由CSDN通过智能技术生成

这个网站http://www.hbc333.com/是一个壁纸图片网站,提供各种分辨率的图片的下载,因此想写一个爬虫脚本批量下载这些图片。

经观察,2560*1600分辨率的图片的网址格式为:http://www.hbc333.com/size/2560x1600/n/ (n是页数),

每张预览图片的地址是:/data/out/253/46659416-watch-dogs-wallpaper.jpg,

而原图的链接则为:http://www.hbc333.com/data/out/253/46659416-watch-dogs-wallpaper.jpg

#coding=utf-8
from urllib import request
import urllib
import re

url1 = "http://www.hbc333.com/size/2560x1600/"          #壁纸网站开始页面

def getMainPage(url):
    page = request.urlopen(url)
    html = page.read()
    return html

#每页的网址为:http://www.hbc333.com/size/2560x1600/n/    n为页数

count = 2
oriUrl = 'http://www.hbc333.com'
while count < 3:
    newUrl = url1 + str(count) + '/'
    count  = count + 1
    print(newUrl)
    html = getMainPage(newUrl)
    print(html)
    dir = []
    html = html.decode('utf-8')  # python3
    dir = re.findall(r'/data/out/[0-9]+/[0-9]+-[a-z]+-[a-z]+.jpg', html)
    #dir = re.findall(r'/data/out/[0-9a-zA-Z]+', html)
    x = 1
    for u in dir:
        #urllib.request.urlretrieve(oriUrl+u,'%s.jpg' %x)
        print(oriUrl+u)
        x = x+1

 

转载于:https://www.cnblogs.com/zjlyyq/p/6445088.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值