Example 3 – using lxml.cssselect to scrape content from a page

CSS selectors have a broad range of query options as described in the Introduction to XPath and CSS selector section, and is often used as an easy alternative to XPath. In the two preceding examples, we explored the XPath to collect the desired information. In this example, we will be using cssselect from lxml to collect relevant data from a single page available on https://developer.ibm.com/announcements/category/data-science/?fa=date%3ADESC&fb=.

To identify a CSS query, we can browse through the page source or use the DevTools. For more detail on using DevTools, refer to the XPath and CSS selectors using DevTools section. In this case, we are identifying and collecting CSS Query ...

Get Hands-On Web Scraping with Python now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.