我在试着从Python上运行Scrapy。我正在查看以下代码(source):
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。我把我的spider项目称为“spider_a”,它指定在spider中爬行的域。在
我要问的是,如果我用以下代码运行我的蜘蛛:
^{pr2}$如何调整上面的示例python代码以实现同样的效果?在
只需导入它并传递到
crawler.crawl()
,如:在scrapy0.19.x中(可能与旧版本一起工作),您可以执行以下操作。在
您甚至可以直接从以下脚本调用命令:
^{pr2}$看看我的答案here。我changed官方的documentation所以现在你的爬虫程序使用你的设置并可以产生输出。在
相关问题 更多 >
编程相关推荐