在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文件的末尾运行print或store to csv命令来检索结果。
当然,这是一个简单的解决方案,但我不明白..提前谢谢。
发布于 2016-09-01 23:04:22
您需要在您使用的任何命令行实用程序中执行runspider命令,例如Cygwin、cmd等。
该命令将在运行该命令的目录中创建一个名为top-stackoverflow-questons.json的文件。
https://stackoverflow.com/questions/39274558
复制相似问题