use beautifulsoup or scrapy to scrape a book store

Solutions on MaxInterview for use beautifulsoup or scrapy to scrape a book store by the best coders in the world

showing results for - "use beautifulsoup or scrapy to scrape a book store"
Eloane
01 Feb 2020
1import scrapy
2
3class bookScraper(scrapy.Spider):
4    name = "bookscrape"
5    
6    start_urls = [
7            'http://books.toscrape.com/'
8        ]
9    def parse(self, response):
10        all_books = response.css('.col-lg-3 ')
11    
12        for book in all_books:
13            img_link = book.css('a img::attr(src)').extract()
14            title = book.css('h3 a::attr(title)').extract()
15            price = book.css('div.product_price p.price_color::text').extract()
16
17            yield {
18                'image_url' : img_link,
19                'book_title' : title,
20                'product_price' : price
21            }
22        next_page = response.css('li.next a::attr(href)').get()
23        if next_page is not None:
24            yield response.follow(next_page, callback = self.parse)