Skip to content

Instantly share code, notes, and snippets.

@AnderRV
Created August 11, 2021 15:12
Show Gist options
  • Save AnderRV/e6544267ac8417d2cc690e15f9c39961 to your computer and use it in GitHub Desktop.
Save AnderRV/e6544267ac8417d2cc690e15f9c39961 to your computer and use it in GitHub Desktop.
data = []
def extract_content(soup):
for product in soup.select('.product'):
data.append({
'id': product.find('a', attrs={'data-product_id': True})['data-product_id'],
'name': product.find('h2').text,
'price': product.find(class_='amount').text
})
print(data)
# [{'id': '759', 'name': 'Bulbasaur', 'price': '£63.00'}, {'id': '729', 'name': 'Ivysaur', 'price': '£87.00'}, ...]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment