码迷,mamicode.com
首页 > 编程语言 > 详细

python爬虫之初步爬图程序

时间:2017-09-11 21:22:19      阅读:211      评论:0      收藏:0      [点我收藏+]

标签:nbsp   findall   coding   http   odi   pre   utf-8   open   mpi   

# -*- coding:utf-8 -*-


import requests, re, os

url = http://tieba.baidu.com/p/5307547413  

header = {
        Accept: */*,
        Accept-Encoding:gzip,deflate,sdch,
        Accept-Language:zh-CN,zh;q=0.8,
        Connection:keep-alive
        }
html = requests.get(url,headers = header)

data = html.content.decode(utf-8)
find = re.compile(r<img class="BDE_Image" src="(.*?).jpg")
result = find.findall(data)

for img_url in result:
    name = img_url.split(/)[-1]
    img_url = img_url+.jpg
    html = requests.get(img_url,headers = header)
    im = html.content
    with open(name+.jpg,wb)as f:
        f.write(im)

 

python爬虫之初步爬图程序

标签:nbsp   findall   coding   http   odi   pre   utf-8   open   mpi   

原文地址:http://www.cnblogs.com/bebox/p/7506682.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!