爬虫03 爬取堆糖图片并保存到本地
# -*- coding: utf-8 -*-
import urllib
import urllib2
import re
i=0
page = 1
url = 'http://www.duitang.com/album/?id=80174265'
user_agent="Mozilla/5.0 (Windows NT 6.1; WOW64; rv:47.0) Gecko/20100101 Firefox/47.0"
headers = { 'User-Agent' : user_agent }
request = urllib2.Request(url,headers=headers)
response = urllib2.urlopen(request)
back=response.read()
imglist=re.findall(r'(http://img[^"]+\.jpeg)"',back)
for img in imglist:
    headers = {
        'Referer': 'http://www.duitang.com/album/?id=80174265',
        'User-Agent': "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/" +
                      "537.36 (KHTML, like Gecko) Chrome/50.0.2661.87 Safari/537.36"}
    print img

    f=open('堆糖图片'+str(i)+'.jpg','w')
    request = urllib2.Request(img, headers=headers)
    imgposition = urllib2.urlopen(request)
    imgget = imgposition.read()
    f.write(imgget)
    i=i+1
阅读更多
版权声明:Talk is cheap,show me the code https://blog.csdn.net/yemoweiliang/article/details/52383755
文章标签: python 爬虫
个人分类: python
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

不良信息举报

爬虫03 爬取堆糖图片并保存到本地

最多只允许输入30个字

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭