爬虫总结(三)-- cloud scrapy

发现了一个比较好玩的东西,scrapinghub,试着玩了一下 cloud scrapy,因为就它是免费的。。最大优点是可以将爬虫可视化。这里就简单记录一下它怎么用。

注册账号 & 新建 scrapy cloud project

scrapyinghub 官网 注册账号
登录后 create project,在新建的项目下,查看 Code & Deploys,找到 API key 和 Project ID

Deploy your project

$ pip install shub

login 并输入 API key

$ shub login
Enter your API key from https://dash.scrapinghub.com/account/apikey
API key: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Validating API key...
API key is OK, you are logged in now.

deploy 并输入 Project ID

$ shub deploy ProjectID
Packing version ed6b3b8-master
Deploying to Scrapy Cloud project "76180"
{"status": "ok", "project": 76180, "version": "ed6b3b8-master", "spiders": 1}
Run your spiders at: https://dash.scrapinghub.com/p/76180/

Schedule your spider

在自己的项目面板下选择 run spider 开启爬虫,也可以通过命令行开启。

shub schedule Zhidao
Spider Zhidao scheduled, job ID: 76153/2/2
Watch the log on the command line:
    shub log -f 2/2
or print items as they are being scraped:
    shub items -f 2/2
or watch it running in Scrapinghub's web interface:
    https://dash.scrapinghub.com/p/76153/job/2/3

看最新的 log 和 items
JOBID格式:2/2, 2/1 …

shub log JOBID
shub items JOBID

或者 Dashboard 查看结果

通过 Dashbord 还可以实时监控 crawler job 的情况,发出的请求数,抓取的 item 数,log 和 error 信息,执行的时间等,都一目了然。

Save items

curl -u APIkey: http://storage.scrapinghub.com/items/76153/2/2 > items.json 

分布式爬虫

cloud scrapy 也提供了分布式爬虫的选择,当然是付费的。

Crawlera

强悍的 Crawlera 提供了防止 ban 的机制,通过 ip、user-agent、cookie 等设置,防止爬虫被禁,详见 billing

完整代码

参考链接:
http://doc.scrapinghub.com/scrapy-cloud.html#deploying-a-scrapy-spider

原文地址: http://www.shuang0420.com/2016/06/15/%E7%88%AC%E8%99%AB%E6%80%BB%E7%BB%93-%E4%B8%89-scrapinghub/

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值