python实战计划学习:爬取美眉图片

import requests

import urllib.request

from bs4 import BeautifulSoup


proxies={'http':"45.33.49.247:25"}


header={

    'User - Agent':'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2729.4 Safari/537.36',

    'cookie':"__qca=P0-169106599-1465266199333; login_token=369fkilkrQ6AluCpf6mn; __utma=222371101.1183090703.1465266203.1465277449.1465353987.3; __utmc=222371101; __utmz=222371101.1465277408.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); __utmv=222371101.|2=registered=2016-06=1^8=registered-day=2016-06-07=1^27=locale=zh-cn=1; _weheartit_anonymous_session=%7B%22page_views%22%3A2%2C%22search_count%22%3A0%2C%22last_searches%22%3A%5B%5D%2C%22last_page_view_at%22%3A1465354248237%7D; auth=yes; _session=ab533615aacac8b381e374ac77283391; _ga=GA1.2.1183090703.1465266203"

}

url='http://weheartit.com/inspirations/taylorswift?page={}'.format(str(i) for i in (0,10))

web_data=requests.get(url,headers=header,proxies=proxies)

url_data = BeautifulSoup(web_data.text, 'lxml')

imgs=url_data.select('img.entry-thumbnail')

download_img=[]

for img in imgs:

    img_list=img.get('src')

    download_img.append(img_list)

folder_path='E://roxy/imgs/'

jpg='{}'.format('.jpg')

for item in download_img:

    urllib.request.urlretrieve(item,folder_path + item[-24:-15]+jpg)'

    print('done')


推荐阅读更多精彩内容