python爬虫(爬取蜂鸟网图片)_创建文件夹
来源:互联网 发布:python 图像分割 编辑:程序博客网 时间:2024/04/28 07:51
import requests,urllib,osfrom bs4 import BeautifulSoupans = 1for page in range(58,69): url = 'http://bbs.fengniao.com/forum/pic/slide_101_6478020_768937' + str(page) + '.html' header = {'User-Agent':'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.109 Safari/537.36'} source_code = requests.get(url,headers = header) plain_text = source_code.text soup = BeautifulSoup(plain_text,'lxml') download_link = [] file_name = '' for pic_tag in soup.find_all('a'): #get the name if pic_tag.get('href')=='/forum/6478020.html': file_name = pic_tag.get('title') if pic_tag.get('class')==['pictureDownload']: download_link.append(pic_tag.get('href')) #file setting folder_path = "D:/spider_things/2016.4.6/" + file_name +"/" if not os.path.exists(folder_path): os.makedirs(folder_path) for item in download_link: urllib.urlretrieve(item,folder_path + str(ans) + '.jpg') print 'download_',ans,'_pics' ans=ans+1
这次爬虫应用了创建文件夹的功能:
#file setting folder_path = "D:/spider_things/2016.4.6/" + file_name +"/" if not os.path.exists(folder_path): os.makedirs(folder_path)上面代码块的意思是:
"os.path.exists(folder_path)"用来判断folder_path这个路径是否存在,如果不存在,就执行“os.makedirs(folder_path)”来创建这个路径
0 0
- python爬虫(爬取蜂鸟网图片)_创建文件夹
- python爬虫(爬取蜂鸟网高像素图片)_空网页,错误处理
- Python 爬取蜂鸟网的照片。。。
- Python 爬取蜂鸟网的照片
- python爬虫爬取图片
- 抓蜂鸟网站图片爬虫
- Python网络爬虫requests、bs4爬取空姐网图片
- Python——网络爬虫(爬取网页图片)
- python 3.3 爬虫之爬取图片
- python爬虫爬取美女图片
- 《python爬虫实战》:爬取图片
- python爬虫-爬取美女图片
- python网络爬虫爬取图片代码
- Python爬虫爬取百度图片
- python爬虫实战 爬取天极图片
- python爬虫----简单的图片爬取
- python爬虫爬取好看的图片
- python 小爬虫爬取美女图片
- SDAU 搜索专题 19 N皇后问题
- Ionic单元测试(Unit Tests)
- 日期的逻辑判断(不用Date和 Calendar)
- Python
- UVA - 10791 Minimum Sum LCM 数学题 ,质因数分解
- python爬虫(爬取蜂鸟网图片)_创建文件夹
- Android消息机制
- Lighttpd使用PHP 出现403错误解决方案
- [经典DP]Employment Planning
- Android Activity的生命周期简单总结
- 专题二 第一道题
- LintCode_157_判断字符串是否没有重复字符
- 总结分享十大iOS开发者最喜爱的库
- #7算法实战和错误类型#