python爬虫之初步爬图程序
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python爬虫之初步爬图程序相关的知识,希望对你有一定的参考价值。
# -*- 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爬虫之初步爬图程序的主要内容,如果未能解决你的问题,请参考以下文章