Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class SomeSpider(scrapy.Spider):
- name = "some_spider"
- start_urls = [
- 'https://<some_site>',
- ]
- def parse(self, response):
- # FIXME: пулучаем все линки на след. страницы
- # нам нужна ссылка, у которой текст -- След.
- next_page = ""
- all_links = response.css('div[data-pagination-num="1"] a')
- for a_sel in all_links:
- if a_sel.css('a::text').get() == 'След.':
- next_page = a_sel.css('a::attr(href)').get()
- if next_page:
- yield response.follow(next_page, callback=self.parse_item)
- def parse_item(self, response):
- l = ItemLoader(
- item=TrainItem(),
- response=response
- )
- l.add_css('name','div.product-item-container > div.product-item div.product-item-title > a::text')
- l.add_css('desc', 'div.product-item-container > div.product-item meta[itemprop="description"]::attr(content)')
- l.add_css('cur_price', 'div.product-item-container > div.product-item span.product-item-price-current::text')
- l.add_css('old_price', 'div.product-item-container > div.product-item span.product-item-price-old::text')
- return l.load_item()
Advertisement
Add Comment
Please, Sign In to add comment