[scrapyd] scrapyd 실행 좌충우돌기

제목: scrapyd 실행 좌충우돌기
# 환경 centos 7.3.1611 , python3.5, virtualenv

# install
$ pip install scrapyd # 1.1.1 설치됨. 2017.4.5일자

# start
$ scrapyd

# but error below

=> TypeError: a bytes-like object is required, not ‘str’
# 아직 python3를 지원하지 않아서 생긴문제
# so reinstall as below
$ pip install scrapyd’==1.2.0a1′
ref: https://github.com/scrapy/scrapyd/issues/143

# start
$ scrapyd

# scrapyd-client install : scrapyd-deploy를 이용하기 위해(deploy를 편하게 해줌)
$ pip install scrapyd-client

# deploy
$ scrapyd-deploy
c.f. 환경설정파일은 https://github.com/scrapy/scrapyd-client

# scheduling
$ curl http://localhost:6800/schedule.json -d project=crawlproject -d spider=crawlspider

# cancel scheduling
$ curl http://localhost:6800/cancel.json -d project=crawlproject -d job=<jobid>

 

# 에러발생 – schedule 명령시 에러 발생
TypeError: __init__() got an unexpected keyword argument ‘_job’
#해결책: 다음과 같이 spider의 __init__ 메서드 signature 수정
원래: def __init__(self):
수정: def __init__(self, **kwargs):

# cf. http://stackoverflow.com/questions/17975472/scrapyd-init-error-when-running-scrapy-spider
# 참고로 scheduling하지 않고 그냥 scrapy crawl spidername 하면 잘 돌아감

# scrapyd를 사용하면서 느낀 점 웹 UI가 좋지 않음.
scrapinghub를 쓰는 것이 좋겠다.

크롤링하면서 크롤하는 곳의 ip를 따진다면 scrapinghub를 사용할 수 없지만 그 외에는
scrapinghub를 쓰는 것이 좋다.

[scrapinghub] pymysql 추가하기

scrapinghub에 pymysql 추가하기

작업용 서버로 centos 7을 사용하고 있다.
파이썬은 한글지원이 필요해서 python3을 사용하고 있다.
python3버전에서는 mysql connect가 pymysql이 설치가 용이하여 이를 선택하였다.

 

개요: scrapinghub를 이용해서 작업을 하는데 pymysql 의존성을 설치하는 방법
요지: requirement.txt에 PyPI에서 받을 수 있는 항목을 적는다.

스택설정

python3을 사용하기 위한 설정

scrapinghub.yml을 다음과 같이 수정

[scrapinghub.yml]

projects:
default: 1111
requirements:
file: ./requirements.txt
stacks:
default: scrapy:1.3-py3

 

의존성추가

참고: 의존성 모듈 추가
c.f. http://help.scrapinghub.com/scrapy-cloud/migrating-dependencies-to-scrapy-cloud-20

$ shub migrate-eggs # scrapinghub의 의존성 모듈을 로컬로 가져온다.

requirement.txt 파일에 다음을 추구한다.

[requirement.txt]

PyMySQL==0.7.10
$ shub deploy # cloud에 올린다.