【发布时间】:2017-09-19 09:58:07
【问题描述】:
我对使用scrapy shell 非常陌生。我搜索了很多但找不到scrapy shell中的打印命令是什么。如果你看看下面的脚本,你就会明白我的意思了。
scrapy shell http://quotes.toscrape.com/ --nolog
for item in response.css(".author"):
author_name = item.css("::text").extract_first()
print(author_name) # What should be the command to print the `author_name`.
所以,如果有人帮助我如何在 scrapy shell 中打印结果,我将不胜感激。谢谢。
【问题讨论】:
-
你试过
pprint吗?from pprint import pprint然后pprint(author_name) -
是的,我试过了。 pprint 不工作。
-
它对我有用。您使用的是哪个版本的 python 和 Scrapy?您确定
author_name在您的情况下不是 None 吗? -
也适合我。您打算只在屏幕上打印它,对吗?
-
Python 3.5 和 scrapy 1.4
标签: python python-3.x web-scraping scrapy scrapy-spider