This is my code for the Coding challenge for the scrape a book store but i am getting only 98% accuracy i tried everything, but i am not getting where i am going wrong.
import scrapy
class BookSpider(scrapy.Spider):
name = “book_spider”
def start_requests(self):
urls = [“http://books.toscrape.com/”,]
for u in urls:
yield scrapy.Request(url=u,callback=self.parse)
def parse(self, response):
for q in response.css("article.product_pod"):
# title = q.css("h3 a::attr(title)").get()
title = q.css("div.image_container a img::attr(alt)").get()
price = q.css("div.product_price p.price_color::text").get()
img_url = q.css("div.image_container a img::attr(src)").get()
yield {
"image_url":img_url,
"book_title":title,
"product_price":price
}
next_page = response.css("li.next a::attr(href)").get()
if next_page is not None:
next_page = response.urljoin(next_page)
yield scrapy.Request(next_page,callback=self.parse)