scrapy 传参

2018-10-24 15:16:46 浏览数 (1)

当爬虫上线时难免会希望动态传参,下面跟着小二一起学传参吧,喽喽喽!

直接上代码: 自己写的spider

代码语言:javascript复制
class MWMSpider(scrapy.Spider):
    name = 'mwm_flowers_spider'

    def __init__(self, **kwargs):
        self.city_name = kwargs['city_name']
        self.run_time = kwargs['run_time']
        self.name=kwargs['name']
        self.latlng=kwargs['latlng']

run.py

代码语言:javascript复制
#!/usr/bin/env python
#-*- coding: utf-8 -*-  
#Create by shengjk1 on  2017/10/25

from scrapy.cmdline import execute
execute(['scrapy', 'crawl', 'mwm_flowers_spider','-alatlng=','-acity_name=成都','-aname=test','-arun_time=20171107'])

0 人点赞