Guest User

Untitled

a guest
Jul 8th, 2020
18
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. class SomeSpider(scrapy.Spider):
  2. name = "some_spider"
  3. start_urls = [
  4. 'https://<some_site>',
  5. ]
  6. def parse(self, response):
  7. # FIXME: пулучаем все линки на след. страницы
  8. # нам нужна ссылка, у которой текст -- След.
  9. next_page = ""
  10. all_links = response.css('div[data-pagination-num="1"] a')
  11. for a_sel in all_links:
  12. if a_sel.css('a::text').get() == 'След.':
  13. next_page = a_sel.css('a::attr(href)').get()
  14. if next_page:
  15. yield response.follow(next_page, callback=self.parse_item)
  16. def parse_item(self, response):
  17.  
  18. l = ItemLoader(
  19. item=TrainItem(),
  20. response=response
  21. )
  22.  
  23. l.add_css('name','div.product-item-container > div.product-item div.product-item-title > a::text')
  24. l.add_css('desc', 'div.product-item-container > div.product-item meta[itemprop="description"]::attr(content)')
  25. l.add_css('cur_price', 'div.product-item-container > div.product-item span.product-item-price-current::text')
  26. l.add_css('old_price', 'div.product-item-container > div.product-item span.product-item-price-old::text')
  27.  
  28. return l.load_item()
Advertisement
Add Comment
Please, Sign In to add comment