Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 13951

Cannot access nested div elements with Beautiful Soup

$
0
0

On this webpage: https://finance.yahoo.com/quote/BRK-B/financials?p=BRK-BI am trying to access the Interest Income row, which is nested under Total Revenue. With Beautiful Soup I cannot seem to access any of the nested rows.

Here is my code:

url = f"https://finance.yahoo.com/quote/{ticker_symbol}/financials"headers = {'User-Agent': 'Mozilla/5.0'}  # Including a user-agentresponse = requests.get(url, headers=headers)if response.status_code != 200:  return "Error: Unable to fetch data"soup = BeautifulSoup(response.content, 'html.parser')total_revenue_div = soup.find('div', {'title': 'Total Revenue'})grandparent_div = total_revenue_div.parent.parent#Access Nested Rowssibling_wrapper_div = grandparent_div.find_next_sibling('div')

Whenever I try, to access the nested rows: I get empty div tags "< div > < /div >". It won't parse the html.

Can anyone please help me select the values in the Interest Income row.


Viewing all articles
Browse latest Browse all 13951

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>