关闭

python--爬去女朋友!

标签: eclipsepython
116人阅读 评论(0) 收藏 举报
分类:

昨天的有点low

今天感觉高级了一点!!

# -*- coding: utf -*-
import requests
from bs4 import BeautifulSoup

url='http://www.ttpaihang.com/vote/rank.php?voteid=1089&page=1'
headers = {'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.93 Safari/537.36'}
ss=requests.get(url,headers=headers)
print(ss.encoding)
ss.encoding='utf-8'
soup=BeautifulSoup(ss.text,'html.parser')
ig=soup.select('img') 
list_ny=[]

for i in range(0,50):
    urll='http://www.ttpaihang.com'
    urll=urll+ig[i]['src']
    list_ny.append(urll)
    
i=0
for s in list_ny:
    headers = {'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.93 Safari/537.36'}
    response = requests.get(s, headers=headers, stream=True)
    print (response.url)
    if response.status_code==200:  
        from contextlib import closing
        with closing(requests.get(s, headers=headers, stream=True)) as response:
            with open('%d.jpg'%i, 'wb') as fd:
                for chunk in response.iter_content(128):
                    fd.write(chunk)
        print(i,'is ok')
    else:
        print(response.status_code)
    i+=1




0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:8797次
    • 积分:267
    • 等级:
    • 排名:千里之外
    • 原创:15篇
    • 转载:11篇
    • 译文:1篇
    • 评论:1条
    文章分类
    最新评论