Example 2 – scraping information from nested links

In this example, we will be scraping details for quotes found in books from http://quotes.toscrape.com/tag/books/. Each individual quote contains certain information, plus a link to the author's detail page, which will also be processed so that we can obtain information regarding the author:

Main page from http://quotes.toscrape.com/tag/books/

In the following code, the elements in keys will be used as keys for output and will contain the Python dictionary. Basically, we will be collecting data for elements in keys:

from pyquery import PyQuery as pqsourceUrl = 'http://quotes.toscrape.com/tag/books/' ...

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.