1 Star 0 Fork 192

zhangjing / PythonClimbInsect

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
dbmeizi.py 1.20 KB
一键复制 编辑 原始数据 按行查看 历史
# -*- coding:utf8 -*-
# 2013.12.36 19:41 wnlo-c209
# 抓取dbmei.com的图片。
from bs4 import BeautifulSoup
import os, sys, urllib2
# 创建文件夹,昨天刚学会
path = os.getcwd() # 获取此脚本所在目录
new_path = os.path.join(path,u'豆瓣妹子')
if not os.path.isdir(new_path):
os.mkdir(new_path)
def page_loop(page=0):
url = 'http://www.dbmeizi.com/?p=%s' % page
content = urllib2.urlopen(url)
soup = BeautifulSoup(content)
my_girl = soup.find_all('img')
# 加入结束检测,写的不好....
if my_girl ==[]:
print u'已经全部抓取完毕'
sys.exit(0)
print u'开始抓取'
for girl in my_girl:
link = girl.get('src')
flink = 'http://www.dbmeizi.com/' + link
print flink
content2 = urllib2.urlopen(flink).read()
with open(u'豆瓣妹子'+'/'+flink[-11:],'wb') as code:#在OSC上现学的
code.write(content2)
page = int(page) + 1
print u'开始抓取下一页'
print 'the %s page' % page
page_loop(page)
page_loop()
print "~~~~~~~~~~~~~~~~~~~~~~~~~~END~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
#为了避免双击的时候直接一闪退出,在最后面加了这么一句
raw_input("Press <Enter> To Quit!")
Python
1
https://gitee.com/zhang-jing151/PythonClimbInsect.git
git@gitee.com:zhang-jing151/PythonClimbInsect.git
zhang-jing151
PythonClimbInsect
PythonClimbInsect
master

搜索帮助

53164aa7 5694891 3bd8fe86 5694891