BeautifulSoup only finds first element in class

  beautifulsoup, python

I’m trying to scrap the following website: https://www.ishares.com/us/products/239726/ishares-core-sp-500-etf

In particular, I’m trying to get all the information from ‘Key Facts’ and ‘Portfolio Characteristics’ etc. However when I run my code, it only returns the first item from each one even though there are 8-10 in each.

I feel like the loop finishes once it finds the first one, how can I get round this?

My code:

import requests
from bs4 import BeautifulSoup
import pandas as pd

URL = 'https://www.ishares.com/us/products/239726/ishares-core-sp-500-etf'
page = requests.get(URL)
soup = BeautifulSoup(page.text, 'html.parser')
for item in soup.find_all('div',{'class':'product-data-list data-points-en_US'}):
    label = item.find(class_='caption').text
    print(label)

Source: Python Questions

LEAVE A COMMENT