Guest User

Untitled

a guest
May 26th, 2018
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. class NikeSpider(scrapy.Spider):
  2. name = 'nike'
  3. allowed_domains = ['nike.com', 'store.nike.com']
  4. start_urls = ['https://www.nike.com/t/air-vapormax-flyknit-utility-running-shoe-XPTbVZzp/AH6834-400']
  5.  
  6. def start_requests(self):
  7. for url in self.start_urls:
  8. yield SplashRequest (
  9. url=url,
  10. callback=self.parse,
  11. args= {
  12. 'wait': 5
  13. }
  14. )
  15.  
  16. def parse(self, response):
  17.  
  18. name = response.xpath('//*[@id="RightRail"]/div/div[1]/div[1]/h1/text()').extract_first()
  19. imageURL = response.css('#PDP > div > div:nth-child(2) > div.css-1jldkv2 > div:nth-child(1) > div > div > div.d-lg-h.bg-white.react-carousel > div > div.slider-container.horizontal.react-carousel-slides > ul > li.slide.selected > div > picture:nth-child(3) > img::attr(src)').extract_first()
  20. category = response.css('#RightRail > div > div.d-lg-ib.mb0-sm.mb8-lg.u-full-width > div.ncss-base.pr12-sm > h2::text').extract_first()
  21. url = response.url
  22.  
  23.  
  24. if name != None and imageURL != None and category != None:
  25. item = ProductItem()
  26. item['name'] = name
  27. item['imageURL'] = imageURL
  28. item['category'] = category
  29. item['URL'] = url
  30.  
  31. yield item
Add Comment
Please, Sign In to add comment