• 通过遍历全网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爬取某学校全网的更多相关文章

  1. 【转载】教你分分钟学会用python爬虫框架Scrapy爬取心目中的女神

    原文:教你分分钟学会用python爬虫框架Scrapy爬取心目中的女神 本博文将带领你从入门到精通爬虫框架Scrapy,最终具备爬取任何网页的数据的能力.本文以校花网为例进行爬取,校花网:http:/ ...

  2. 以豌豆荚为例,用 Scrapy 爬取分类多级页面

    本文转载自以下网站:以豌豆荚为例,用 Scrapy 爬取分类多级页面 https://www.makcyun.top/web_scraping_withpython17.html 需要学习的地方: 1 ...

  3. Scrapy爬取美女图片 (原创)

    有半个月没有更新了,最近确实有点忙.先是华为的比赛,接着实验室又有项目,然后又学习了一些新的知识,所以没有更新文章.为了表达我的歉意,我给大家来一波福利... 今天咱们说的是爬虫框架.之前我使用pyt ...

  4. scrapy爬取西刺网站ip

    # scrapy爬取西刺网站ip # -*- coding: utf-8 -*- import scrapy from xici.items import XiciItem class Xicispi ...

  5. scrapy爬取豆瓣电影top250

    # -*- coding: utf-8 -*- # scrapy爬取豆瓣电影top250 import scrapy from douban.items import DoubanItem class ...

  6. scrapy爬取极客学院全部课程

    # -*- coding: utf-8 -*- # scrapy爬取极客学院全部课程 import scrapy from pyquery import PyQuery as pq from jike ...

  7. scrapy爬取全部知乎用户信息

    # -*- coding: utf-8 -*- # scrapy爬取全部知乎用户信息 # 1:是否遵守robbots_txt协议改为False # 2: 加入爬取所需的headers: user-ag ...

  8. Scrapy爬取Ajax(异步加载)网页实例——简书付费连载

    这两天学习了Scrapy爬虫框架的基本使用,练习的例子爬取的都是传统的直接加载完网页的内容,就想试试爬取用Ajax技术加载的网页. 这里以简书里的优选连载网页为例分享一下我的爬取过程. 网址为: ht ...

  9. Scrapy爬取静态页面

    Scrapy爬取静态页面 安装Scrapy框架: Scrapy是python下一个非常有用的一个爬虫框架 Pycharm下: 搜索Scrapy库添加进项目即可 终端下: #python2 sudo p ...

随机推荐

  1. N多条短信,用什么算法从中找出相似内容的来?

    创建树,每个字符为一个节点,对于同一位置字符相同的共用一个节点.最后找出具有公共节点的短信.例如:MessageA "hello,world"MessageB "hell ...

  2. 基于视觉反馈的步进电机X-Y平台控制

    关键词:步进电机.XY平台.视觉反馈 用途:工业自动化 文章类型:原理介绍.随笔纪念 @Author:VShawn(singlex@foxmail.com) @Date:2017-05-01 @Lab ...

  3. I2C通信

    项目之前研究了I2C通信协议的实现,完成FPGA对视频解码芯片SAA7111A的初始化配置,设计实现了I2C主机对从机(SAA7111A)32个寄存器的写操作,因此只简单实现了I2C的写时序. 这次重 ...

  4. TimeQuest学习总结

    1. 基本时钟约束:creat_clock 2. 生成时钟约束:creat_generated_clock 3. I/O输入输出约束:(1)纯组合逻辑:set_max_delay & set_ ...

  5. tarball源码安装

    软件最原始的安装方法 用tarball来安装升级make命令执行make ,会在当前路径下搜索makefile这个文本文件,这个文件中记录了源码如何编译的详细信息.软件开发商通常会写一个检测程序,检测 ...

  6. Python+Django+Bootstrap 框架环境搭建

    1.安装python和pip(python.pip安装自行百度,pip是一个安装和管理 Python 包的工具) 2.配置python环境变量(python和scripts目录都需要配置) 3.安装D ...

  7. C++模板专门化与重载

    最近在复习C++有关知识,又重新看<<Effective C++>>,收获颇丰.原来以前看这边书,好多地方都是浅尝辄止.<<Effective C++>> ...

  8. Codeforces Round #395 (Div. 2) C. Timofey and a tree

    地址:http://codeforces.com/contest/764/problem/C 题目: C. Timofey and a tree time limit per test 2 secon ...

  9. winform + INotifyPropertyChanged + IDataErrorInfo + ErrorProvider实现自动验证功能

    一个简单的Demo.百度下载链接:http://pan.baidu.com/s/1sj4oM2h 话不多说,上代码. 1.实体类定义: class Student : INotifyPropertyC ...

  10. Nginx 域名跳转

    域名跳转 就是实现URL的跳转和隐藏真实地址,基于Perl语言的正则表达式规范.平时帮助我们实现拟静态,拟目录,域名跳转,防止盗链等 . 域名跳转配置 1.多域名指定一个域名重定向 # 空格分割域名 ...