gazpacho logo gazpacho: attributes

1 2 3 4 5 6
Notes

Sometimes you're not interested in parsing the text from an html element but rather you're interested in retreiving attributes. This also holds true for the website that we are currently scraping.

The code that nicely parses the website is listed below.

url = "https://pypi.org/project/pandas/#history"

from gazpacho import get, Soup
html = get(url)
soup = Soup(html)
cards = soup.find('a', {'class': 'card'})

def parse_card(card):
    version_number = card.find('p', {'class': 'release__version'}, strict=True).text
    timestamp = card.find('time').attrs['datetime']
    return {'version': version_number, 'timestamp': timestamp}

[parse_card(c) for c in cards]