python3 爬取豆瓣妹子
2015-08-30 17:34
423 查看
__author__ = 'NFD' # -*- coding:UTF-8 -*- import urllib.request import os import re import time from bs4 import BeautifulSoup webheader = {'User-Agent':'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:23.0) Gecko/20100101 Firefox/23.0'} img_index = 1 def processDouban(page_url): list_url = page_url #print(all_data) if __name__ == '__main__': pageIndex = 2525 index = 1 #os.mkdir('doubanimages') while pageIndex > 0: pageUrl = 'http://www.dbmeinv.com/?pager_offset='+ str(pageIndex) try: list_req = urllib.request.Request(url=pageUrl, headers=webheader) list_Page=urllib.request.urlopen(list_req) all_data = list_Page.read().decode('utf-8') current_soup = BeautifulSoup(all_data, 'html.parser') current_list = current_soup.find_all('img',{'class':'height_min'}) for list in current_list: #print(list['href']) time.sleep(1) print(time.strftime("%H:%M:%S ") +'处理图片: '+list['src']) try: file=open('doubanimages//' + str(index) + '.jpg', "wb") req = urllib.request.Request(list['src'], headers=webheader) webPage=urllib.request.urlopen(req) data = webPage.read() file.write(data) except: print('打开图片失败') file.flush() file.close() index += 1 #img_index += 1 else: file.flush() file.close() index += 1 except: pageIndex-=1 else: pageIndex-=1
相关文章推荐
- Python教程
- python 对数函数
- multiprocessing在python中的高级应用-共享数据与同步
- Python程序退出方式(sys.exit() os._exit() os.kill() os.popen(...))
- 一个简单的python练习
- python 爬虫3 新浪微博 爬虫 实战
- Python3Hovercraft创建impressive.js演示文档(一)
- 在windows上安装pip
- 【Python基础】Python面向对象 - 1
- 用virtualenv管理python3运行环境
- 《Unicode之痛》摘抄
- python 脚本学习(一)
- python实现断点续传下载文件
- python 内置函数
- multiprocessing在python中的高级应用-进程池
- Python入门
- Python编程错误之IndentationError: unexpected indent
- python switch
- 【python】17个新手常见Python运行时错误
- multiprocessing在python中的高级应用-IPC 之 Pipe