Created
April 12, 2021 13:58
-
-
Save ian-kerins/23a083509a9097a3bba62c91b8a10cc1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def parse(self, response): | |
di = json.loads(response.text) | |
pos = response.meta['pos'] | |
dt = datetime.now().strftime('%Y-%m-%d %H:%M:%S') | |
for result in di['organic_results']: | |
title = result['title'] | |
snippet = result['snippet'] | |
link = result['link'] | |
item = {'title': title, 'snippet': snippet, 'link': link, 'position': pos, 'date': dt} | |
pos += 1 | |
yield item | |
next_page = di['pagination']['nextPageUrl'] | |
if next_page: | |
yield scrapy.Request(get_url(next_page), callback=self.parse, meta={'pos': pos}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment