Element traversing, attributes, and pseudo-classes

pyquery has a large set of attributes and methods that can be deployed to obtain the desired content. In the following examples, we'll identify the implementation from the code that's found in this section:

>>> page('title') #find element <title>[<title>]>>> page.find('title').text() #find element <title> and return text content'Welcome to Python.org'>>> page.find('meta[name="description"]').attr('content')'The official home of the Python Programming Language'>>> page.find('meta[name="keywords"]').attr('content')'Python programming language object oriented web free open source software license documentation download community'>>> buttons = page('a.button').html() #return HTML content for ...

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.