我正在尝试从 Python 运行 Scrapy。我正在查看这段代码(source http://doc.scrapy.org/en/0.16/topics/practices.html):
from twisted.internet import reactor
from scrapy.crawler import Crawler
from scrapy.settings import Settings
from scrapy import log
from testspiders.spiders.followall import FollowAllSpider
spider = FollowAllSpider(domain='scrapinghub.com')
crawler = Crawler(Settings())
crawler.configure()
crawler.crawl(spider)
crawler.start()
log.start()
reactor.run() # the script will block here
我的问题是我对如何调整此代码来运行我自己的蜘蛛感到困惑。我将我的蜘蛛项目称为“spider_a”,它指定要在蜘蛛本身内爬行的域。
我要问的是,如果我使用以下代码运行我的蜘蛛:
scrapy crawl spider_a
如何调整上面的示例 python 代码以实现相同的功能?
只需导入它并传递到crawler.crawl()
, like:
from testspiders.spiders.spider_a import MySpider
spider = MySpider()
crawler.crawl(spider)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)