Python网络爬虫1
来源:互联网 发布:mac air使用教程视频 编辑:程序博客网 时间:2024/06/06 01:42
简单爬取新浪新闻网的部分新闻:
代码:选用技术(requsets,BeautifulSoup)
import requestsfrom bs4 import BeautifulSoupres = requests.get('http://news.sina.com.cn/china/')res.encoding = 'utf-8'soup = BeautifulSoup(res.text, 'html.parser')for news in soup.select('.blk122'): print(len(news)) #news涵盖了标题和网址,所以是双倍len // 整除 num = len(news) // 2 for i in range(0, num): if i <= len(news): href = news.select('a')[i]['href'] titl = news.select('a')[i].text print(titl, href)
结果:
23
沈阳楼市变脸:从鼓励大学生零首付购房到限售 http://news.sina.com.cn/c/nd/2017-08-22/doc-ifykcppy0119890.shtml
合肥疯狂楼市终结:开发商雇人拉客看房 http://news.sina.com.cn/c/nd/2017-08-22/doc-ifykcypq2732441.shtml
吴敦义盼尽快结束蔡英文执政 恢复两岸和平发展 http://news.sina.com.cn/c/gat/2017-08-21/doc-ifykcppy0107438.shtml
肃清虞海燕流毒 兰州多部门一把手拟集中调整 http://news.sina.com.cn/c/sz/2017-08-21/doc-ifykcypq2633944.shtml
中纪委点名落马官员:两面人典型 演技登峰造极 http://news.sina.com.cn/c/nd/2017-08-21/doc-ifykcppy0095600.shtml
徐玉玉去世一周年 徐父:生活得继续在打工还债 http://news.sina.com.cn/c/nd/2017-08-21/doc-ifykcqaw0550502.shtml
中南大学研发出耐3000℃烧蚀新材料 http://news.sina.com.cn/o/2017-08-21/doc-ifykcqaw0544760.shtml
“占中”分子被收监是政治检控?林郑月娥回应 http://news.sina.com.cn/c/gat/2017-08-21/doc-ifykcppy0072341.shtml
北京能疏解多少人到雄安新区?专家称三五十万 http://news.sina.com.cn/o/2017-08-21/doc-ifykcqaw0525325.shtml
- [Python]网络爬虫1
- Python网络爬虫1
- 【Python爬虫1】网络爬虫简介
- python 网络爬虫入门 1
- Python网络爬虫(1)
- python 3.0 网络爬虫 1
- Python网络爬虫演示-1
- python网络爬虫day'1
- Python网络爬虫1 ---- windows下搭建爬虫框架scrapy
- [Python]网络爬虫(1):你要干什么?
- Python网络爬虫(1)获取网页
- 《用python写网络爬虫》笔记1
- 异步网络爬虫的Python实现(1)
- python网络爬虫(1)--抓取图片
- Python-网络爬虫之BeautifulSoup(1)
- python 网络爬虫代码
- Python实现网络爬虫
- Python实现网络爬虫
- python爬取糗事百科
- #支持向量机(SVM)与其理论发展(1)
- MySQL 5.7 EXPLAIN EXTENDED语句说明
- 次小生成树
- debug有感
- Python网络爬虫1
- vue.js 2.0实现的简单分页
- React实现按钮控制倒计时
- 基于vue2.0的一个分页组件
- dns-prefetch对网站速度能提升有多少?详解dns-prefetch
- Hibernate的入门
- Practical Microservices-Packt Publishing(2017) 读书笔记
- Python标准异常总结
- 基于vuejs菜单实现