python爬虫由浅入深13--scrapy基础实战·爬取哈理工教务在线公告
来源:互联网 发布:老股民炒股软件 编辑:程序博客网 时间:2024/04/29 06:32
1.站点分析
打开哈理工教务在线,进入教务公告页面,将每页显示量设置成为一个较大的值,例如10000。。。
对应站点为:http://jwzx.hrbust.edu.cn/homepage/infoArticleList.do;jsessionid=0A7BC5FE8C48FB877683ABB970E4F6D6.TH?sortColumn=publicationDate&columnId=354&sortDirection=-1&pagingPage=1&pagingNumberPer=10000
而所要抓取的文章标题的源码如下
那么可知公告文章标题的xpaht为:
"//ul[@class='articleList']/li/div/a/text()"
2.打开cmd,输入 scrapy startproject jwzx
3.打开jwzx/jwzx/spiders,创建一个新文件jwzxSpider.py
编写代码:
import scrapyclass jwzxSpider(scrapy.Spider): name = 'jwzx' start_urls = ['http://jwzx.hrbust.edu.cn/homepage/infoArticleList.do;jsessionid=0A7BC5FE8C48FB877683ABB970E4F6D6.TH?sortColumn=publicationDate&columnId=354&sortDirection=-1&pagingPage=1&pagingNumberPer=10000'] def parse(self, response): titles = response.xpath("//ul[@class='articleList']/li/div/a/text()").extract() urls = response.xpath("//ul[@class='articleList']/li/div/a/@href").extract() for i in range(len(urls)): print(titles[i]) print(urls[i]) with open("C:/Users/kfc/Desktop/jwzx.txt",'a',encoding='utf-8') as f: f.write(titles[i].strip()+'\n'+'http://jwzx.hrbust.edu.cn/homepage/'+urls[i]+'\n')
4.然后进入cmd,在项目的根目录下运行scrapy crawl jwzx(这个jwzx就是刚才jwzxSpider.py文件中的name字段)
5.输出接过保存至本地文件:
阅读全文
0 0
- python爬虫由浅入深13--scrapy基础实战·爬取哈理工教务在线公告
- python爬虫由浅入深12---scrapy框架的基础入门
- Python爬虫框架Scrapy实战
- Python爬虫框架Scrapy实战
- python爬虫获取郑大教务在线成绩数据
- python 爬虫实战--登陆学校教务系统获取成绩信息
- Python爬虫实战——模拟登录教务系统
- Python爬虫框架Scrapy实战之安装
- python爬虫由浅入深10---pyquery库的基础与使用
- python爬虫由浅入深11---selenium的基础与使用
- python爬虫正方教务系统
- python爬虫正方教务系统
- Scrapy爬虫实战
- Scrapy-爬虫实战
- scrapy爬虫实战教程
- 自学Python之Scrapy爬虫:(一)爬虫基础
- Python爬虫框架Scrapy实战之抓取户外数据
- Python爬虫框架Scrapy实战之批量抓取招聘
- struts2拦截器与过滤器的理解
- 初次使用PyCharm,下载安装及汉化
- java开发-JVM监控调优
- Delphi读写ini文件示例
- Cow Contest POJ
- python爬虫由浅入深13--scrapy基础实战·爬取哈理工教务在线公告
- Centos7下postfix+Dovecot+cyrus-sasl搭建个人局域网邮件服务器(测试使用)
- 深度学习和自然语言处理的应用和脉络4-隐语义模型SVD,PLSA,LDA,LFM-推荐系统
- FPGA和CPLD的区别
- 存储过程之四—游标
- leetcode 15. 3sum && 16. 3Sum Closest && 18. 4Sum
- Resume(简历)
- Python 面向对像
- 重定向和管道