Issue
I am new to Scrapy and I made a simple program to get the title tag from the page qoutes.toscrape.com. I tried to get the tag in the terminal and it works, but when I try to extract it as a json file, I get an empty json file.
scrapy crawl zillow -o output.json
What could be the problem?
Here is my code:
import scrapy
class ZillowSpider(scrapy.Spider):
name = "zillow"
start_urls = [
"https://quotes.toscrape.com/"
]
def parse(self, response):
price = response.css("title::text").get()
I tried googling and chat gpt but can't find the solution to this problem.
Solution
Inside .parse
method you need to yield all the data you want to extract and save:
def parse(self, response):
price = response.css("title::text").get()
yield {"price": price}
Answered By - Kirill Varchenko
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.