[英]Scrapy: How to run spider from other python script twice or more?
[英]Python Scrapy - Run Spider
在Windows计算机上运行Python27 ...尝试使用Scrapy
遵循基本的Scrapy教程@ http://doc.scrapy.org/en/latest/intro/overview.html
我创建了以下蜘蛛并将其保存为Test2 @ C:\\ Python27 \\ Scrapy
import scrapy
class StackOverflowSpider(scrapy.Spider):
name = 'stackoverflow'
start_urls = ['http://stackoverflow.com/questions?sort=votes']
def parse(self, response):
for href in response.css('.question-summary h3 a::attr(href)'):
full_url = response.urljoin(href.extract())
yield scrapy.Request(full_url, callback=self.parse_question)
def parse_question(self, response):
yield {
'title': response.css('h1 a::text').extract_first(),
'votes': response.css('.question .vote-count-post::text').extract_first(),
'body': response.css('.question .post-text').extract_first(),
'tags': response.css('.question .post-tag::text').extract(),
'link': response.url,
}
下一步告诉我使用scrapy runspider stackoverflow_spider.py -o top-stackoverflow-questions.json
运行蜘蛛
但是我不知道在哪里运行那行代码。
我习惯在python文件的末尾运行打印或存储到csv命令以便检索结果。
当然,这是一个简单的解决方法,但我不明白..在此先感谢。
您将需要在使用的任何命令行实用程序(例如Cygwin,cmd等)中执行runspider命令。
该命令将在运行命令的目录中创建一个名为top-stackoverflow-questions.json的文件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.