【发布时间】:2016-09-01 14:41:54
【问题描述】:
在 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 命令以检索结果。
当然,这是一个简单的解决方案,但我没有得到它.. 在此先感谢。
【问题讨论】:
标签: python-2.7 scrapy scrapy-spider