How to select dictionary key recursively in Python?

A common challenge when it comes to web scraping JSON data is extracting specific data fields from nested JSON datasets which might be unpredictable. For this, recursive dictionary key selection can be used through tools like nested-lookup (pip install nested-lookup):

from nested_lookup import nested_lookup

data = {
    "props-23341s": {
        "information_key_23411": {
            "data": {
                "phone": "+1 555 555 5555",
            }
        }
    }
}
print(nested_lookup("phone", data)[0])
"+1 555 555 5555"

nested-lookup is a Python native package for recursive dictionary key lookup or even modification. Though, it's great in web scraping for large JSON Dataset parsing.

Provided by Scrapfly

This knowledgebase is provided by Scrapfly data APIs, check us out! 👇