Skip to content

Instantly share code, notes, and snippets.

@amankharwal
Created March 3, 2021 16:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amankharwal/6f6c5853c09c5181f53a71c8f96b81ef to your computer and use it in GitHub Desktop.
Save amankharwal/6f6c5853c09c5181f53a71c8f96b81ef to your computer and use it in GitHub Desktop.
import scrapy
class StackOverflow(scrapy.Spider):
name = 'stackoverflow'
start_urls = ['http://stackoverflow.com/questions?sort=votes']
def parse(self, response):
parse_question
for href in response.css('.question-summary h3 a::attr(href)'):
full_url = response.urljoin(href.extract())
yield scrapy.Request(full_url, callback=self.parse_question)
def parse_question(self, response):
yield {
'title': response.css('h1 a::text').extract_first(),
'votes': response.css('.question .vote-count-post::text').extract_first(),
'body': response.css('.question .post-text').extract_first(),
'tags': response.css('.question .post-tag::text').extract(),
'link': response.url,
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment