python爬虫爬取糗百成人图片单线程版本
来源:互联网 发布:阿里云ecs 数据库管理 编辑:程序博客网 时间:2024/04/30 08:49
爬取糗百成人图片的所有图图,先来个单线程版本的:
#encoding:utf-8#单线程简单版本import requestsimport osfrom bs4 import BeautifulSoupimport threadingimport urllib.requestFIRST_PAGE_URL = 'http://www.qiubaichengren.com/{}.html'PAGE_URL_LIST = []gLock = threading.Lock()for x in range(1,100): page_url = FIRST_PAGE_URL.format(x) PAGE_URL_LIST.append(page_url)def get_page(page_url): response = requests.get(page_url) content = response.content soup = BeautifulSoup(content, 'lxml') src = soup.find_all('div',class_='mala-text') imgs = soup.find_all('img') for img in src: url = img.find('img') link = url.get('src') title = url.get('alt') split_list = link.split('/') final = split_list.pop() t_split_list = final.split('.') suffix = t_split_list.pop() filename = title + '.' + suffix #名字加后缀 # print(filename,link) print(link) download_image(link,filename)def download_image(url,filename): path = os.path.join('images', filename) urllib.request.urlretrieve(url, filename=path) #print(link) # print(imgs) # title = soup.select('#wrapper > div > div.ui-main > div.mala-text > div.mtitle > a') #imgs = soup.select('img') #print(imgs) # for img in imgs: # tmp = img.get('src') # print('-----') # title = img.attrs["alt"] # print(title) ##get_page('http://www.qiubaichengren.com/1.html')def main(): #get_page('http://www.qiubaichengren.com/1.html') for pageurl in PAGE_URL_LIST: print(pageurl) get_page(pageurl)if __name__ == "__main__": main()
阅读全文
0 0
- python爬虫爬取糗百成人图片单线程版本
- python爬虫爬取糗百成人图片多线程版本
- python爬虫系列一:爬取糗百成人的妹子图片(urllib2)
- python-单线程爬虫
- python爬虫系列二:爬取糗百成人的妹子图片(requests+正则)
- python爬虫系列三:爬取糗百成人的妹子图片(scrapy框架+正则)
- python单线程网络爬虫
- python单线程爬虫(一)
- Python爬虫之<单线程爬虫>
- Python爬虫(单线程爬虫(三))
- Python爬虫入门学习--(单线程爬虫)
- python学习中一个单线程爬虫
- Python 网络爬虫单线程版
- Python--正则表达式/单线程网络爬虫
- python 单线程与多线程爬虫
- Python爬虫学习(单线程爬虫(一))
- Python爬虫学习(单线程爬虫(二))
- Python爬虫学习笔记(2)-单线程爬虫
- OpenCV3.3 VS2017环境配置
- bzoj1047 [HAOI2007]理想的正方形(单调队列)
- 进程与线程的区别与联系
- PhalApi-RabbitMQ基于PhalApi专业队列拓展
- 前端小案例分享:京东电梯式导航制作
- python爬虫爬取糗百成人图片单线程版本
- sql注入小总结
- 如何快速创建一个Spring Boot项目
- spring 配置
- Ubuntu 安装和配置Tomcat
- 解决SpringBoot框架下利用jdbcTemplate插入mysql数据库中文乱码问题
- sql判断一个表是否存在 以及表中的字段是否存在
- test
- 上海大数据高峰论坛—暨OurwayBI新品发布会即将开启!