Skip to content

Instantly share code, notes, and snippets.

@ian-kerins
Created April 12, 2021 13:58
Show Gist options
  • Save ian-kerins/23a083509a9097a3bba62c91b8a10cc1 to your computer and use it in GitHub Desktop.
Save ian-kerins/23a083509a9097a3bba62c91b8a10cc1 to your computer and use it in GitHub Desktop.
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