赞
踩
一、爬取新浪新闻思路
1、创建scrapy项目
2、分析新浪新闻网站静态页面代码
3、编写对应的xpath公式
4、写代码
二、项目代码
步骤1、创建scrapy项目
scrapy startproject mycwpjt
步骤2、分析新浪网站静态代码
随便打开一个新浪新闻网,新闻
可以看到地址为
http://news.sina.com.cn/gov/xlxw/2018-03-21/doc-ifyskeue0491622.shtml
点开其他新闻也为.shtml结尾
那么我们可以考虑从新浪首页,针对性爬取后缀为.shtml的网页
步骤3、编写对应的xpath公式
在html的页面head中可以看到标题在title中
新时代 去奋斗|新时代|奋斗|改革_新浪新闻当前页面的链接在meta中
由此可以写出xpath为
标题:/html/head/title/text()
链接: //meta[@property='og:url']/@content
步骤4、编写代码
创建爬虫文件
scrapy genspider -t crawl bangbing sina.com.cn
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。