Last active
September 4, 2018 13:37
-
-
Save cargan/53ac8288b03984b32a19e840fffac452 to your computer and use it in GitHub Desktop.
This file contains 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
# -*- coding: utf-8 -*- | |
# 1. create virtual environment: virtualenv venv | |
# 2. install scrapy: ./venv/bin/pip install scrapy | |
# 3. run spider: ./venv/bin/scrapy runspider spider.py -o saras_delfi.json | |
import scrapy | |
class SarasDelfiSpider(scrapy.Spider): | |
name = "saras" | |
start_urls = [ | |
'https://www.delfi.lt/temos/sarunas-jasikevicius', | |
] | |
def parse(self, response): | |
for quote in response.css('div.headline'): | |
yield { | |
'title': quote.css('h3.headline-title').xpath('a/text()').extract_first(), | |
'excerpt': quote.css('p.headline-lead').xpath('text()').extract_first() | |
} | |
next_page = response.css('a.next:not([class^="next hidden"])::attr("href")').extract_first() | |
if next_page is not None: | |
yield response.follow(next_page, self.parse) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment