通过使用scrapy爬取某学校全网
- 通过遍历全网url 实现爬取全网内容
- 忽略“.doc"等文件网页暂不处理,只爬取整个页面,不做清洗
- spider.py
# -*- coding: utf-8 -*-
import scrapy
from WSYU.items import WsyuItem
import datetime
from urllib import parse
from scrapy.http import Request class WsyuSpider(scrapy.Spider):
name = 'wsyu'
allowed_domains = ['wsyu.edu.cn']
# start_urls = ['http://www.wsyu.edu.cn/',]
start_urls = ['http://www.wsyu.edu.cn/',]
html_url_set = []
other_url_set =[]
wenjian_end = ["@", ".pdf", ".jpg", ".gif", ".png", ".doc", ".xls", ".ppt", ".mp3", ".rar", ".zip",] def do_fiter(self,all_urls):
for one_url in all_urls:
if any(u in one_url for u in self.wenjian_end):
self.other_url_set.append(one_url)
else:
pass
return all_urls def parse(self, response):
# 获取所有的地址链接
all_urls = response.xpath('//a/@href').extract()
all_urls = [parse.urljoin(response.url,url) for url in all_urls]
all_urls1 = self.do_fiter(all_urls)
# all_urls2 = list(filter(lambda x:True if x.startswith('\'http') else False, all_urls1))
if all_urls1!=None:
for one_url in all_urls1:
if one_url not in self.html_url_set and one_url not in self.other_url_set:
self.html_url_set.append(one_url)
# yield self.make_requests_from_url(one_url)
yield Request(parse.urljoin(response.url,one_url),callback=self.download_parse)
# 回调函数默认为parse else:
yield Request(url=self.html_url_set[-2],callback=self.parse) def download_parse(self,response): item = WsyuItem()
item['url'] = response.url
# print(item['url'])
item['content'] = response.text
# print(item['content'])
item['create_time'] = datetime.datetime.now()
# print(item['create_time'])
yield item
# yield Request(url=response.url ,callback=self.parse)
yield self.make_requests_from_url(response.url) - 源代码放在github上了:https://github.com/longbigbeard/scrapy_demo/tree/master/WSYU
- 以上
通过使用scrapy爬取某学校全网的更多相关文章
- 【转载】教你分分钟学会用python爬虫框架Scrapy爬取心目中的女神
原文:教你分分钟学会用python爬虫框架Scrapy爬取心目中的女神 本博文将带领你从入门到精通爬虫框架Scrapy,最终具备爬取任何网页的数据的能力.本文以校花网为例进行爬取,校花网:http:/ ...
- 以豌豆荚为例,用 Scrapy 爬取分类多级页面
本文转载自以下网站:以豌豆荚为例,用 Scrapy 爬取分类多级页面 https://www.makcyun.top/web_scraping_withpython17.html 需要学习的地方: 1 ...
- Scrapy爬取美女图片 (原创)
有半个月没有更新了,最近确实有点忙.先是华为的比赛,接着实验室又有项目,然后又学习了一些新的知识,所以没有更新文章.为了表达我的歉意,我给大家来一波福利... 今天咱们说的是爬虫框架.之前我使用pyt ...
- scrapy爬取西刺网站ip
# scrapy爬取西刺网站ip # -*- coding: utf-8 -*- import scrapy from xici.items import XiciItem class Xicispi ...
- scrapy爬取豆瓣电影top250
# -*- coding: utf-8 -*- # scrapy爬取豆瓣电影top250 import scrapy from douban.items import DoubanItem class ...
- scrapy爬取极客学院全部课程
# -*- coding: utf-8 -*- # scrapy爬取极客学院全部课程 import scrapy from pyquery import PyQuery as pq from jike ...
- scrapy爬取全部知乎用户信息
# -*- coding: utf-8 -*- # scrapy爬取全部知乎用户信息 # 1:是否遵守robbots_txt协议改为False # 2: 加入爬取所需的headers: user-ag ...
- Scrapy爬取Ajax(异步加载)网页实例——简书付费连载
这两天学习了Scrapy爬虫框架的基本使用,练习的例子爬取的都是传统的直接加载完网页的内容,就想试试爬取用Ajax技术加载的网页. 这里以简书里的优选连载网页为例分享一下我的爬取过程. 网址为: ht ...
- Scrapy爬取静态页面
Scrapy爬取静态页面 安装Scrapy框架: Scrapy是python下一个非常有用的一个爬虫框架 Pycharm下: 搜索Scrapy库添加进项目即可 终端下: #python2 sudo p ...
随机推荐
- SQL 数据库无法附加,提示 MDF" 已压缩
SQL 数据库无法附加,提示 MDF" 已压缩,但未驻留在只读数据库或文件组中.必须将此文件解压缩 1右键点击数据库所在的文件夹, 2点击属性,在常规选项卡中点击高级, 3在弹出的窗口中 ...
- Django模板继承后出现logo图片无法加载的问题
父文件:index.html <!DOCTYPE html> <html lang="en"> <head> <title>{% b ...
- Redis与Memcached的比较(转)
原文:http://blog.nosqlfan.com/html/3729.html 这两年Redis火得可以,Redis也常常被当作Memcached的挑战者被提到桌面上来.关于Redis与Memc ...
- 详细介绍Redis的几种数据结构以及使用注意事项(转)
原文:详细介绍Redis的几种数据结构以及使用注意事项 1. Overview 1.1 资料 <The Little Redis Book>,最好的入门小册子,可以先于一切文档之前看,免费 ...
- [今日干货]一个吸粉效果也不错的APP
最近陌陌被封很厉害,今天给大家分享一个吸粉效果也不错的APP——悦跑圈,日吸几百粉没问题~ 1.首先下载APP悦跑圈,用手机号码注册. 2.改写资料和头像,最好用一个女性头像,真实点的,不是网图,增加 ...
- day3-python的基础类源码解析——collection类
1.计数器(counter) Counter是对字典类型的补充,用于追踪值的出现次数. ps:具备字典的所有功能 + 自己的功能 我们从中挑选一些相对常用的方法来举例: 在上面的例子我们可以看出,co ...
- URAL - 1900 Brainwashing Device
While some people travel in space from planet to planet and discover new worlds, the others who live ...
- hadoop27---netty中handler的执行顺序
Netty是基于Java NIO的网络应用框架. Netty是一个NIO client-server(客户端服务器)框架,使用Netty可以快速开发网络应用,例如服务器和客户端协议.Netty提供了一 ...
- Tomcat 优化相关知识
---------(Tomcat Listener)----------- Tomcat 性能的因素是内存泄露.Server标签中可以配置多个Listener,其中 JreMemoryLeakPrev ...
- 数据结构(二) 树Tree
五.树 树的定义 树的逻辑表示:树形表示法.文氏图表示法.凹入表示法.括号表示法. 结点:表示树中的元素,包括数据项及若干指向其子树的分支. 结点的度:结点拥有的子树树:树的度:一 ...