CSS selectors and your Browser Console

Like the notation we used to extract using cssselect, CSS selectors are patterns used for selecting HTML elements. Here are some examples of common selectors you should know:

Select any tag: * Select by tag <a>: a Select by class of "link": .link  Select by tag <a> with class "link": a.link Select by tag <a> with ID "home": a#home Select by child <span> of tag <a>: a > span Select by descendant <span> of tag <a>: a span Select by tag <a> with attribute title of "Home": a[title=Home]

The cssselect library implements most CSS3 selectors, and details on unsupported features (primarily browser interactions) are available at https://cssselect.readthedocs.io/en/latest/#supported-selectors.

The CSS3 specification ...

Get Python Web Scraping - Second Edition 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.