如果希望spider定向爬取,就需要给spider传入参数
首先在spider类中定义初始化函数
def __init__(self, start_urls=None, number=5, *args, **kwargs):
super(DouBanMovieSituationSpider, self).__init__(*args, **kwargs)
self.start_urls = start_urls
self.number = int(commentNum)
调用时使用
scrapy crawl xxxSpider -a start_urls=xxxxxx -a number=number
想传多少个参数,就在参数前加多少个 -a……
有同学是使用pycharm里面的调用python语句来模拟执行cmd的,则将python语句改为“
from scrapy.cmdline import execute
execute(['scrapy', 'crawl', 'xxxSpider',"-a","start_urls=xxxx","-a","number=666"])
是不是挺简单的,赶快配置吧!
网友评论