通过使用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 ...
随机推荐
- 棣小天儿的第一个python程序
根据给定的年月日,以数字形式打印出日期 months = [ 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'Augu ...
- Python中的不同进制的语法和转换
不同进制的书写方式 八进制(Octal) 0o377 十六进制(Hex) 0xFF 二进制(Binary) 0b11111111 不同进制之间的转换 python提供了三个内置的函数,能够用来在不同进 ...
- tensorflow 的 tutorial 的卷积神经网络的例子 convolutional.py
具体的网址在这里: https://github.com/tensorflow/tensorflow/tree/r0.12/tensorflow/models 一个卷积神经网络用于股票分析的例子: ...
- 解决Webpack 安装sass时出现的错误
webpack环境下,加载css需要 css-loader 和 style-loader. css-loader:使用类似@import和url(...)的方法实现 require的功能: style ...
- pt-osc原理
pt-osc原理 1.检查设置环境 测试db是否可连通,并且验证database是否存在 SET SESSION innodb_lock_wait_timeout=1 //InnoDB事务等待行锁的超 ...
- PM,RD,FE,UE,UI,QA,OP,DBA,BRD,MRD,PRD,FSD全称解析
PM 项目经理( Project Manager ) 从职业角度,是指企业建立以项目经理责任制为核心,对项目实行质量.安全.进度.成本管理的责任保证体系和全面提高项目管理水平设立的重要管理 ...
- style、 currentStyle、 runtimeStyle、getComputedStyle区别分析
1.obj.style只能获得内嵌样式(inline Style)就是写在Tag里面的,他访问不到那些链接的外部css和在head中用<style>声明的style. 所以必须认识到在那些 ...
- HDU 5703
题意:给你一个数n,问将n分为正整数和的方案数.如n=3共四种,1 1 1 , 1 2 , 2 1 ,3 . 思路:隔板法,n个1,有n-1个空位,每个空位可以选择是否插入隔板,插入k(0<=k ...
- spark启动
注意在启动spark时候要指定参数 要不就死启动的单机版的 /usr/local/spark-1.5.2-bin-hadoop2.6/bin/spark-shell \ --master spark: ...
- 一图看懂join、left join、right join、fulljoin间的区别
INNER JOIN 关键字在表中存在至少一个匹配时返回行. LEFT JOIN 关键字从左表(table1)返回所有的行,即使右表(table2)中没有匹配.如果右表中没有匹配,则结果为 NULL. ...