aboutsummaryrefslogtreecommitdiff
path: root/crawler/neodarznet/spiders/scrape.py
blob: a32a3e46bac60da578fd82e7c64fd815796f7098 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# -*- coding: utf-8 -*-
import scrapy
from scrapy.spiders import CrawlSpider, Rule
from scrapy.linkextractors import LinkExtractor
from scrapy import Selector

class ScrapSpider(CrawlSpider):
    name = "scrape"
    allow_domains = ['neodarz.net']
    start_urls = [
        'https://neodarz.net/',
    ]

    rules = [
            Rule(
                LinkExtractor(
                    canonicalize=True,
                    unique=True,
                    allow_domains="neodarz.net",
                    deny=".*\.neodarz\.net.*"
                ),
                follow=True,
                callback="parse_items"
            )
    ]


    def start_requests(self):
        for url in self.start_urls:
            yield scrapy.Request(url, callback=self.parse, dont_filter=True)

    def parse_items(self, response):
        sel = Selector(response)
        yield {
                'url': response.url,
                'title': response.css('title::text').extract_first(),
                'content': ''.join(sel.select("//div[@class='bodya']//text()").extract()).strip()
        }