1
2
mirror of https://github.com/vimagick/dockerfiles synced 2024-06-26 00:38:37 +00:00
dockerfiles/scrapyd/README.md

127 lines
3.4 KiB
Markdown
Raw Normal View History

2015-05-29 01:19:56 +00:00
scrapyd
=======
2014-12-01 13:19:37 +00:00
2015-07-02 14:19:37 +00:00
![](http://dockeri.co/image/vimagick/scrapyd)
2017-01-22 05:32:27 +00:00
[scrapy][1] is an open source and collaborative framework for extracting the
2015-06-20 09:02:23 +00:00
data you need from websites. In a fast, simple, yet extensible way.
2015-06-20 08:45:20 +00:00
2017-01-22 05:32:27 +00:00
[scrapyd][2] is a service for running Scrapy spiders. It allows you to deploy
2015-06-20 09:02:23 +00:00
your Scrapy projects and control their spiders using a HTTP JSON API.
2017-01-22 05:32:27 +00:00
[scrapyd-client][3] is a client for scrapyd. It provides the scrapyd-deploy
2015-06-20 09:29:44 +00:00
utility which allows you to deploy your project to a Scrapyd server.
2017-01-22 05:32:27 +00:00
[scrapy-splash][4] provides Scrapy+JavaScript integration using Splash.
2015-09-20 10:19:43 +00:00
2017-01-22 05:32:27 +00:00
[pillow][5] is the Python Imaging Library to support the ImagesPipeline.
2016-05-26 12:30:59 +00:00
2016-06-02 17:01:52 +00:00
This image is based on `debian:jessie`, 5 latest python packages are installed:
2015-06-20 08:45:20 +00:00
- `scrapy`: git+https://github.com/scrapy/scrapy.git
- `scrapyd`: git+https://github.com/scrapy/scrapyd.git
2015-06-20 09:29:44 +00:00
- `scrapyd-client`: git+https://github.com/scrapy/scrapyd-client.git
2017-01-22 05:32:27 +00:00
- `scrapy-splash`: git+https://github.com/scrapinghub/scrapy-splash.git
2016-05-26 12:30:59 +00:00
- `pillow`: git+https://github.com/python-pillow/Pillow.git
2014-12-01 13:19:37 +00:00
2016-06-02 17:01:52 +00:00
Please use this as base image for your own project.
2014-12-01 13:19:37 +00:00
2016-08-10 03:32:53 +00:00
## docker-compose.yml
```yaml
scrapyd:
image: vimagick/scrapyd
ports:
- "6800:6800"
2017-01-22 05:32:27 +00:00
volumes:
- ./data:/var/lib/scrapyd
- /usr/local/lib/python2.7/dist-packages
2016-08-10 03:32:53 +00:00
restart: always
scrapy:
image: vimagick/scrapyd
command: bash
volumes:
- .:/code
working_dir: /code
restart: always
```
2015-06-20 09:02:23 +00:00
## Run it as background-daemon for scrapyd
2015-06-20 08:45:20 +00:00
2016-08-10 03:32:53 +00:00
```bash
$ docker-compose up -d scrapyd
$ docker-compose logs -f scrapyd
$ docker cp scrapyd_scrapyd_1:/var/lib/scrapyd/items .
$ tree items
└── myproject
└── myspider
└── ad6153ee5b0711e68bc70242ac110005.jl
2015-06-20 08:45:20 +00:00
```
2016-08-10 03:32:53 +00:00
```bash
2016-08-04 11:31:24 +00:00
$ mkvirtualenv webbot
$ pip install scrapy scrapyd-client
$ scrapy startproject myproject
$ cd myproject
$ setvirtualenvproject
$ scrapy genspider myspider mydomain.com
$ scrapy edit myspider
$ scrapy list
$ vi scrapy.cfg
$ scrapyd-client deploy
$ curl http://localhost:6800/schedule.json -d project=myproject -d spider=myspider
2016-08-10 03:32:53 +00:00
$ firefox http://localhost:6800
2016-08-04 11:31:24 +00:00
```
File: scrapy.cfg
2016-08-10 03:32:53 +00:00
```ini
2016-08-04 11:31:24 +00:00
[settings]
default = myproject.settings
[deploy]
url = http://localhost:6800/
project = myproject
```
2015-06-20 09:02:23 +00:00
## Run it as interactive-shell for scrapy
2015-06-20 08:45:20 +00:00
2016-08-10 03:32:53 +00:00
```bash
2015-06-20 08:45:20 +00:00
$ cat > stackoverflow_spider.py << _EOF_
import scrapy
class StackOverflowSpider(scrapy.Spider):
name = 'stackoverflow'
start_urls = ['http://stackoverflow.com/questions?sort=votes']
def parse(self, response):
for href in response.css('.question-summary h3 a::attr(href)'):
full_url = response.urljoin(href.extract())
yield scrapy.Request(full_url, callback=self.parse_question)
def parse_question(self, response):
yield {
'title': response.css('h1 a::text').extract()[0],
'votes': response.css('.question .vote-count-post::text').extract()[0],
'body': response.css('.question .post-text').extract()[0],
'tags': response.css('.question .post-tag::text').extract(),
'link': response.url,
}
_EOF_
2016-08-10 03:32:53 +00:00
$ docker-compose run --rm scrapy
2015-06-20 08:45:20 +00:00
>>> scrapy runspider stackoverflow_spider.py -o top-stackoverflow-questions.json
>>> cat top-stackoverflow-questions.json
>>> exit
```
[1]: https://github.com/scrapy/scrapy
[2]: https://github.com/scrapy/scrapyd
2015-06-20 09:29:44 +00:00
[3]: https://github.com/scrapy/scrapyd-client
2015-09-20 10:19:43 +00:00
[4]: https://github.com/scrapinghub/scrapy-splash
2016-05-26 12:30:59 +00:00
[5]: https://github.com/python-pillow/Pillow