如何实现数据共享Dashboard中的数据操作

开源爬虫哪个好_一起开源
您所在的位置:&&&&
开发语言:C#&&&&&&&&收录时间:(755)
开发语言:python&&&&&&&&收录时间:(126)
开发语言:C#&&&&&&&&收录时间:(1498)
开发语言:java&&&&&&&&收录时间:(285)
开发语言:go&&&&&&&&收录时间:(165)
开发语言:go&&&&&&&&收录时间:(208)
开发语言:java&&&&&&&&收录时间:(285)
开发语言:ruby&&&&&&&&收录时间:(159)
开发语言:java&&&&&&&&收录时间:(348)
开发语言:C#&&&&&&&&收录时间:(571)  试想一下,前面做的实验和例子都只有一个spider。然而,现实的开发的爬虫肯定不止一个。既然这样,那么就会有如下几个问题:1、在同一个项目中怎么创建多个爬虫的呢?2、多个爬虫的时候是怎么将他们运行起来呢?
  说明:本文章是基于前面几篇文章和实验的基础上完成的。如果您错过了,或者有疑惑的地方可以在此查看:
  一、创建spider
  1、创建多个spider,scrapy genspider spidername domain
scrapy genspider
  通过上述命令创建了一个spider name为CnblogsHomeSpider的爬虫,start_urls为/的爬虫
  2、查看项目下有几个爬虫scrapy list
[root@bogon cnblogs]# scrapy list
CnblogsHomeSpider
CnblogsSpider
  由此可以知道我的项目下有两个spider,一个名称叫CnblogsHomeSpider,另一个叫CnblogsSpider。
  更多关于scrapy命令可参考:
  二、让几个spider同时运行起来
  现在我们的项目有两个spider,那么现在我们怎样才能让两个spider同时运行起来呢?你可能会说写个shell脚本一个个调用,也可能会说写个python脚本一个个运行等。然而我在上看到。的确也有不上前辈是这么实现。然而官方文档是这么介绍的。
  1、Run Scrapy from a script
import scrapy
from scrapy.crawler import CrawlerProcess
class MySpider(scrapy.Spider):
# Your spider definition
process = CrawlerProcess({
'USER_AGENT': 'Mozilla/4.0 ( MSIE 7.0; Windows NT 5.1)'
process.crawl(MySpider)
process.start() # the script will block here until the crawling is finished
  这里主要通过来实现在脚本里运行一个spider。更多的例子可以在此查看:
  2、Running multiple spiders in the same process
通过CrawlerProcess
import scrapy
from scrapy.crawler import CrawlerProcess
class MySpider1(scrapy.Spider):
# Your first spider definition
class MySpider2(scrapy.Spider):
# Your second spider definition
process = CrawlerProcess()
process.crawl(MySpider1)
process.crawl(MySpider2)
process.start() # the script will block here until all crawling jobs are finished
通过CrawlerRunner
import scrapy
from twisted.internet import reactor
from scrapy.crawler import CrawlerRunner
from scrapy.utils.log import configure_logging
class MySpider1(scrapy.Spider):
# Your first spider definition
class MySpider2(scrapy.Spider):
# Your second spider definition
configure_logging()
runner = CrawlerRunner()
runner.crawl(MySpider1)
runner.crawl(MySpider2)
d = runner.join()
d.addBoth(lambda _: reactor.stop())
reactor.run() # the script will block here until all crawling jobs are finished
通过CrawlerRunner和链接(chaining) deferred来线性运行
from twisted.internet import reactor, defer
from scrapy.crawler import CrawlerRunner
from scrapy.utils.log import configure_logging
class MySpider1(scrapy.Spider):
# Your first spider definition
class MySpider2(scrapy.Spider):
# Your second spider definition
configure_logging()
runner = CrawlerRunner()
@defer.inlineCallbacks
def crawl():
yield runner.crawl(MySpider1)
yield runner.crawl(MySpider2)
reactor.stop()
reactor.run() # the script will block here until the last crawl call is finished
  这是官方文档提供的几种在script里面运行spider的方法。
  三、通过自定义scrapy命令的方式来运行
  创建项目命令可参考:
  1、创建commands目录
mkdir commands
  注意:commands和spiders目录是同级的
  2、在commands下面添加一个文件crawlall.py
  这里主要通过修改scrapy的crawl命令来完成同时执行spider的效果。crawl的源码可以在此查看:
from mands import ScrapyCommand
from scrapy.crawler import CrawlerRunner
from scrapy.utils.conf import arglist_to_dict
class Command(ScrapyCommand):
requires_project = True
def syntax(self):
return '[options]'
def short_desc(self):
return 'Runs all of the spiders'
def add_options(self, parser):
ScrapyCommand.add_options(self, parser)
parser.add_option("-a", dest="spargs", action="append", default=[], metavar="NAME=VALUE",
help="set spider argument (may be repeated)")
parser.add_option("-o", "--output", metavar="FILE",
help="dump scraped items into FILE (use - for stdout)")
parser.add_option("-t", "--output-format", metavar="FORMAT",
help="format to use for dumping items with -o")
def process_options(self, args, opts):
ScrapyCommand.process_options(self, args, opts)
opts.spargs = arglist_to_dict(opts.spargs)
except ValueError:
raise UsageError("Invalid -a value, use -a NAME=VALUE", print_help=False)
def run(self, args, opts):
#settings = get_project_settings()
spider_loader = self.crawler_process.spider_loader
for spidername in args or spider_loader.list():
print "*********cralall spidername************" + spidername
self.crawler_process.crawl(spidername, **opts.spargs)
self.crawler_process.start()
  这里主要是用了self.crawler_process.spider_loader.list()方法获取项目下所有的spider,然后利用self.crawler_process.crawl运行spider
  3、commands命令下添加__init__.py文件
touch __init__.py
  注意:这一步一定不能省略。我就是因为这个问题折腾了一天。囧。。。就怪自己半路出家的吧。
  如果省略了会报这样一个异常
Traceback (most recent call last):
File "/usr/local/bin/scrapy", line 9, in &module&
load_entry_point('Scrapy==1.0.0rc2', 'console_scripts', 'scrapy')()
File "/usr/local/lib/python2.7/site-packages/Scrapy-1.0.0rc2-py2.7.egg/scrapy/cmdline.py", line 122, in execute
cmds = _get_commands_dict(settings, inproject)
File "/usr/local/lib/python2.7/site-packages/Scrapy-1.0.0rc2-py2.7.egg/scrapy/cmdline.py", line 50, in _get_commands_dict
cmds.update(_get_commands_from_module(cmds_module, inproject))
File "/usr/local/lib/python2.7/site-packages/Scrapy-1.0.0rc2-py2.7.egg/scrapy/cmdline.py", line 29, in _get_commands_from_module
for cmd in _iter_command_classes(module):
File "/usr/local/lib/python2.7/site-packages/Scrapy-1.0.0rc2-py2.7.egg/scrapy/cmdline.py", line 20, in _iter_command_classes
for module in walk_modules(module_name):
File "/usr/local/lib/python2.7/site-packages/Scrapy-1.0.0rc2-py2.7.egg/scrapy/utils/misc.py", line 63, in walk_modules
mod = import_module(path)
File "/usr/local/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
ImportError: No module named commands
  一开始怎么找都找不到原因在哪。耗了我一整天,后来到/上得到了网友的帮助。再次感谢万能的互联网,要是没有那道墙该是多么的美好呀!扯远了,继续回来。
  4、settings.py目录下创建setup.py(这一步去掉也没影响,不知道官网帮助文档这么写有什么具体的意义。)
from setuptools import setup, find_packages
setup(name='scrapy-mymodule',
entry_points={
'mands': [
'mands:crawlall',
  这个文件的含义是定义了一个crawlall命令,mands为命令文件目录,crawlall为命令名。
  5. 在settings.py中添加配置:
COMMANDS_MODULE = 'mands'
  6. 运行命令scrapy crawlall
  最后源码更新至此:
阅读(...) 评论()&&&&使用python编写的scrapy爬虫项目
使用python编写的scrapy爬虫项目
数据挖掘文本分类语料库爬取的爬虫,使用scrapy编写
若举报审核通过,可奖励20下载分
被举报人:
buptzhengchaojie
举报的资源分:
请选择类型
资源无法下载
资源无法使用
标题与实际内容不符
含有危害国家安全内容
含有反动色情等内容
含广告内容
版权问题,侵犯个人或公司的版权
*详细原因:
VIP下载&&免积分60元/年(1200次)
您可能还需要
开发技术下载排行【Git 项目推荐】使用 scrapy 爬取网络上的信息
(window.slotbydup=window.slotbydup || []).push({
id: '2611110',
container: s,
size: '240,200',
display: 'inlay-fix'
您当前位置: &
[ 所属分类
| 时间 2015 |
作者 红领巾 ]
douban_scrapy
感谢豆瓣小组提供数据来源
#: 安装必要
sudo pip install scrapy
sudo pip install pymongo
#: 下载图片到本地,并且保存相关信息到MongoDB中.
scrapy crawl haixiuzu
#: 生成本地相册需要的json data.
python check.py
#: 建立本地http server
python -m SimpleHTTPServer 80
#: 打开浏览器输入http://localhost/gallary
已实现的功能
爬取大家的发贴信息(标题、标题URL、作者、作者URL等),以及下载妹子图片到本地
爬取用户地理位置信息,方便联(yue)系(pao)
增加RandomUserAgent功能,防止被BAN
增加延时抓取功能,防止被BAN
由于下载妹子图片较多,故采用hash方法分散到多个目录进行管理,提高打开文件夹速度
下载妹子图片的同时生成缩略图,为计划做的【妹子图库网站】做准备
计划实现的功能
本地相册功能,可以在浏览器内预览图,通过快捷键j,k,space等对图片进行翻页,加红心,删除等功能
本地相册功能打算借鉴(fgallery)[ http://www.thregr.org/~wavexx/software/fgallery/demo/ ]
如果图片对应的topic已被管理员删除,则高亮显示(一般被删的都是尺度较大的图片)
提交建议,需求,Bug报告
本文开发(python)相关术语:python基础教程 python多线程 web开发工程师 软件开发工程师 软件开发流程
转载请注明本文标题:本站链接:
分享请点击:
1.凡CodeSecTeam转载的文章,均出自其它媒体或其他官网介绍,目的在于传递更多的信息,并不代表本站赞同其观点和其真实性负责;
2.转载的文章仅代表原创作者观点,与本站无关。其原创性以及文中陈述文字和内容未经本站证实,本站对该文以及其中全部或者部分内容、文字的真实性、完整性、及时性,不作出任何保证或承若;
3.如本站转载稿涉及版权等问题,请作者及时联系本站,我们会及时处理。
登录后可拥有收藏文章、关注作者等权限...
意识到自由意志是上天赐予的礼物的人,只有在奋力抗争之后,才知道如何善用!
手机客户端
,专注代码审计及安全周边编程,转载请注明出处:http://www.codesec.net
转载文章如有侵权,请邮件 admin[at]codesec.net}

我要回帖

更多关于 数据结构中的算法实现 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信