Extract Item Title and Price with Selector

  • Share this:

Code introduction


This function extracts the item title and price from a provided selector and returns them as a dictionary.


Technology Stack : Scrapy, CSS selectors

Code Type : Scrapy crawler handler

Code Difficulty : Intermediate


                
                    
def parse_item(item, selector):
    # Extract the item title and price from the provided selector
    title = selector.css('h1.title::text').get()
    price = selector.css('span.price::text').get()
    
    # Return a dictionary with the extracted data
    return {
        'title': title,
        'price': price
    }