设置
用刮擦我刮房屋广告
根据ad-overview page,我获得一个列表,其中hrefs链接到各个广告。通过for循环,hrefs被发送到第二个解析器函数,以获得每个广告的外壳特征
def parse(self, response):
# for href in list with hrefs
for href in response.xpath(
'//*[@id]/@href',
).extract()[1:-1]:
yield scrapy.Request(response.urljoin(href),
callback=self.parse_ad)
def parse_ad(self, response):
# here follows code to obtain housing characteristics per ad
yield {'char1': char1,
'char2': char2,}
这个很好用
除了hrefs,我还从广告概述页面获取了一个邮政编码列表
response.xpath('//*[@id]/div[1]/div/div[1]/div[1]/div[2]/meta').extract()
最终我希望
yield {'char1': char1,
'char2': char2,
'postal code': postal_code}
但我不知道该怎么做
href
及其对应的postal_code
postal_code
移到parse_ad()
下的yield
函数我该怎么办
要从一个回调方法“继续”到另一个回调方法,请使用^{} :
相关问题 更多 >
编程相关推荐