import scrapy
class BookScraper(scrapy.Spider):
name = “book_scraper”
def start_requests(self):
urls = [
"http://books.toscrape.com/catalogue/page-1.html"
]
for url in urls:
yield scrapy.Request(url=url,callback = self.parse)
def parse(self,response):
page = response.url.split("/")[-3]
filename = "books-%s.html" % page
for b in response.css("article.product_pod"):
name = b.css('h3 a::attr(title)').get()
image_url = b.css('div.image_container a img::attr(src)').get()
price = b.css('div.product_price p.price_color::text.split("a")[-1]').get()
availability = b.css('p.instock.availability').get()
yield {
'name': name,
'img_url': img_url,
'price':price,
'availability':availability
}
next_page = response.css('li.nexta::attr(href)').get()
if next_page is not None:
next_page = response.urljoin(next_page)
yield scrapy.Request(next_page,callback = self.parse)
i am getting empty json file after running this code . What changes can i make in this code?