July 2019
Beginner to intermediate
350 pages
8h 13m
English
In this section, we will be using CSS Selectors with their extensions such as ::text and ::attr along with extract() and strip(). Similar to response.xpath(), available to run XPath expressions, CSS Selectors can be run using response.css(). The css() selector matches the elements using the provided expressions:
'''Using CSS Selectors'''def parse(self, response): print("Response Type >>> ", type(response)) rows = response.css("div.quote") #root element for row in rows: item = QuotesItem() item['tags'] = row.css('div.tags > meta[itemprop="keywords"]::attr("content")').extract_first() item['author'] = row.css('small[itemprop="author"]::text').extract_first() item['quote'] = row.css('span[itemprop="text"]::text').extract_first() ...
Read now
Unlock full access