response.meta.get()中的多个参数

时间:2018-06-09 14:36:06

标签: python python-3.x web-scraping scrapy scrapy-spider

在scrapy中null多个参数如何适合?如果它是可行的那么response.meta.get("something","someotherthing")someotherthing的关系如何?

我搜索了很多,但找不到我之后的确切答案。

1 个答案:

答案 0 :(得分:1)

在scrapy中

response.meta它只是一个普通的python dict,而作为一个python dict,它的方法get是无安全的 - 当第二个参数是默认值时如果第一个参数不在dict中,则放置。

例如: 而response.meta['unknown_key']会引发KeyError异常, response.meta.get('unknown_key')将返回None,并且 response.meta.get('unknown_key', 'abc')将返回abc