通过使用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 ...
随机推荐
- 笔记-django学习链接
form表单学习 https://www.cnblogs.com/weiman3389/p/6225075.html python字符串replace()方法 https://www.cnblogs. ...
- Python生成器是什么
生成器是 Python 初级开发者最难理解的概念之一,虽被认为是 Python 编程中的高级技能,但在各种项目中可以随处见到生成器的身影,你得去理解它.使用它.甚至爱上它. 提到生成器,总不可避免地要 ...
- gophercloud openstack networking 源码分析
1.network 部分 // Package networks contains functionality for working with Neutron network resources. ...
- 如何实现redis集群?
由于Redis出众的性能,其在众多的移动互联网企业中得到广泛的应用.Redis在3.0版本前只支持单实例模式,虽然现在的服务器内存可以到100GB.200GB的规模,但是单实例模式限制了Redis没法 ...
- R语言seq()函数用法
1.seq() 用来生成一组数字的函数. Usage: ## Default S3 method:seq(from = 1, to = 1, by = ((to - from)/(length.out ...
- js判断background颜色明暗色调,以设置白/黑字体颜色
整理自:jscolor.js插件 this.styleElement.style.color = this.isLight() ? '#000' : '#FFF'; this.isLight ...
- And Design:拓荒笔记——Upload上传
And Design:拓荒笔记——Upload上传 上传前
- TP框架基础2
---恢复内容开始--- [空操作和空控制器处理] 空操作:就没有指定的操作方法 空控制器:没有指定控制器 http://网址/index.php/Home/User/login http://网址/ ...
- Spring 之通过 XML 装配 bean
1.关于 使用传统标签还是 c- p- 命名空间定义的标签, 我的观点是能用 c- p- 命名空间定义的标签 就不用 传统标签(这样会比较简洁... 2.强依赖使用构造器注入,可选性依赖使用属性注入 ...
- 记一次网卡报错ERROR,some other host already uses address
提示IP地址冲突,但是此IP确实没有被其他Server占用 解决如下: 编辑此文件 搜索arping 将下面几行注释掉 保存退出 激活网卡 此时IP地址已生效 下面是我的系统版本 (一般应该不会出现这 ...