为什么我在执行 python 脚本后在终端中看不到输出?
Why am I not seeing output in the terminal after executing python script?
我正在学习教程 @: https://blog.scrapinghub.com/category/scrapy-tips-from-the-pros/ ~ 代码似乎执行得很好,但我没有看到终端的任何输出。我仍在尝试弄清楚如何使用 "stack trace with python..., to see if there is a issue on the back-end" ,问题是执行脚本后我在终端中看不到任何输出。任何帮助都会很棒..
import scrapy
class SpidyQuotesViewStateSpider(scrapy.Spider):
name = 'spidyquotes-viewstate'
start_urls = ['http://quotes.toscrape.com/search.aspx']
download_delay = 1.5
def parse(self, response):
for author in response.css('select#author > option ::attr(value)').extract():
yield scrapy.FormRequest(
'http://quotes.toscrape.com/filter.aspx',
formdata={
'author': author,
'__VIEWSTATE': response.css('input#__VIEWSTATE::attr(value)').extract_first()
},
callback=self.parse_tags
)
def parse_tags(self, response):
for tag in response.css('select#tag > option ::attr(value)').extract():
yield scrapy.FormRequest(
'http://quotes.toscrape.com/filter.aspx',
formdata={
'author': response.css(
'select#author > option[selected] ::attr(value)'
).extract_first(),
'tag': tag,
'__VIEWSTATE': response.css('input#__VIEWSTATE::attr(value)').extract_first()
},
callback=self.parse_results,
)
def parse_results(self, response):
for quote in response.css("div.quote"):
yield {
'quote': quote.css('span.content ::text').extract_first(),
'author': quote.css('span.author ::text').extract_first(),
'tag': quote.css('span.tag ::text').extract_first(),
}
给定的代码没有活动执行。这只不过是一个 class 定义。要获得输出,您需要在本教程中继续编写驱动程序(主)程序,该程序将实例化 class 的对象并进行一两次调用以实际抓取给定的网站。
除非您的程序崩溃(引发致命异常),否则您不会得到 "stack trace"。这不是你实施的东西 "use".
将文件保存到你项目的spider目录下,然后执行
scray crawl spidyquotes-viewstate -o viewstate.json
结果将在您当前目录的 viewstate.json
中。
我正在学习教程 @: https://blog.scrapinghub.com/category/scrapy-tips-from-the-pros/ ~ 代码似乎执行得很好,但我没有看到终端的任何输出。我仍在尝试弄清楚如何使用 "stack trace with python..., to see if there is a issue on the back-end" ,问题是执行脚本后我在终端中看不到任何输出。任何帮助都会很棒..
import scrapy
class SpidyQuotesViewStateSpider(scrapy.Spider):
name = 'spidyquotes-viewstate'
start_urls = ['http://quotes.toscrape.com/search.aspx']
download_delay = 1.5
def parse(self, response):
for author in response.css('select#author > option ::attr(value)').extract():
yield scrapy.FormRequest(
'http://quotes.toscrape.com/filter.aspx',
formdata={
'author': author,
'__VIEWSTATE': response.css('input#__VIEWSTATE::attr(value)').extract_first()
},
callback=self.parse_tags
)
def parse_tags(self, response):
for tag in response.css('select#tag > option ::attr(value)').extract():
yield scrapy.FormRequest(
'http://quotes.toscrape.com/filter.aspx',
formdata={
'author': response.css(
'select#author > option[selected] ::attr(value)'
).extract_first(),
'tag': tag,
'__VIEWSTATE': response.css('input#__VIEWSTATE::attr(value)').extract_first()
},
callback=self.parse_results,
)
def parse_results(self, response):
for quote in response.css("div.quote"):
yield {
'quote': quote.css('span.content ::text').extract_first(),
'author': quote.css('span.author ::text').extract_first(),
'tag': quote.css('span.tag ::text').extract_first(),
}
给定的代码没有活动执行。这只不过是一个 class 定义。要获得输出,您需要在本教程中继续编写驱动程序(主)程序,该程序将实例化 class 的对象并进行一两次调用以实际抓取给定的网站。
除非您的程序崩溃(引发致命异常),否则您不会得到 "stack trace"。这不是你实施的东西 "use".
将文件保存到你项目的spider目录下,然后执行
scray crawl spidyquotes-viewstate -o viewstate.json
结果将在您当前目录的 viewstate.json
中。