Giter Site home page Giter Site logo

Passing arguments to scraper about scrapydweb HOT 5 CLOSED

my8100 avatar my8100 commented on July 22, 2024
Passing arguments to scraper

from scrapydweb.

Comments (5)

echoocking avatar echoocking commented on July 22, 2024 1

schedule.json is correct. __init__ func needs change like this could solve my problem.

 def __init__(self, mgo_db=None, mgo_table=None, *args, **kwargs):
        mgo_conn = get_mgo_client()
        self.mgo_table = mgo_conn[mgo_db][mgo_table]
        super(MtopSpider, self).__init__()

init take any spider arguments and copy them to spider as attrbutes

thank you very much 👍 hhhhhhh~~

from scrapydweb.

my8100 avatar my8100 commented on July 22, 2024

It should work if you add '-d symbol=APPL' in the additional text box!

from scrapydweb.

ohenrik avatar ohenrik commented on July 22, 2024

Thank you, this worked 🎉

from scrapydweb.

echoocking avatar echoocking commented on July 22, 2024

i want pass params to spider , so i use init func to get -a params like this

    def __init__(self, mgo_db, mgo_table):
        mgo_conn = get_mgo_client()
        self.mgo_table = mgo_conn[mgo_db][mgo_table]
        super(MtopSpider, self).__init__()

and add
'-d mgo_db=mtop
-d mgo_table=taolijin'
in the additional text box

but i got

2019-03-20 21:33:09 [twisted] CRITICAL: 
Traceback (most recent call last):
  File "/root/.local/share/virtualenvs/scrapyd-server-b9lo-2yl/lib/python3.7/site-packages/twisted/internet/defer.py", line 1418, in _inlineCallbacks
    result = g.send(result)
  File "/root/.local/share/virtualenvs/scrapyd-server-b9lo-2yl/lib/python3.7/site-packages/scrapy/crawler.py", line 79, in crawl
    self.spider = self._create_spider(*args, **kwargs)
  File "/root/.local/share/virtualenvs/scrapyd-server-b9lo-2yl/lib/python3.7/site-packages/scrapy/crawler.py", line 102, in _create_spider
    return self.spidercls.from_crawler(self, *args, **kwargs)
  File "/root/.local/share/virtualenvs/scrapyd-server-b9lo-2yl/lib/python3.7/site-packages/scrapy_redis/spiders.py", line 153, in from_crawler
    obj = super(RedisSpider, self).from_crawler(crawler, *args, **kwargs)
  File "/root/.local/share/virtualenvs/scrapyd-server-b9lo-2yl/lib/python3.7/site-packages/scrapy/spiders/__init__.py", line 51, in from_crawler
    spider = cls(*args, **kwargs)
TypeError: __init__() got an unexpected keyword argument '_version'

what shoud i do for this? thanks a lot :)

from scrapydweb.

my8100 avatar my8100 commented on July 22, 2024

Check out https://doc.scrapy.org/en/latest/topics/spiders.html#spider-arguments

image

from scrapydweb.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.