#๐ I am try to scrap data from Yahoo Finance I can't seem to do it.
30 messages ยท Page 1 of 1 (latest)
@rose rampart
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
!rule 5
5. Do not provide or request help on projects that may violate terms of service, or that may be deemed inappropriate, malicious, or illegal.
Yahoo Finance does allowed web scraping.
From: https://finance.yahoo.com/sectors/technology/ I am trying to get the total market cap from the technology sector. This number:
Yahoo Finance's Technology performance dashboard help you quickly analyze & examine stock performance across the Technology sector using dozens of metrics and views.
right click inspect
Copy element?
it shows where its in the html
<div class="value svelte-e2k9sg">15.581T</div>
import requests
from bs4 import BeautifulSoup
site=requests.get("https://finance.yahoo.com/sectors/technology/?guccounter=1")
html=BeautifulSoup(site.text,"html.parser")
parse the site
Ok got it
this is the part I have been getting confused about: tech_market_cap= soup.find('span', {'class': 'value svelte-e2k9sg'}).text
I'm not sure how to do it
it should be as simple as soup.find("div",_class='value svelte-e2k9sg').text
I keep getting 11 as the output when Im trying to get 15.581T
for me it gives an error bc it can find it
import requests
from bs4 import BeautifulSoup
site = requests.get("https://finance.yahoo.com/sectors/technology/?guccounter=1")
html = BeautifulSoup(site.text, "html.parser")
tech_mctotal = html.find("div", class_='value svelte-e2k9sg').text
print(tech_mctotal)
I get 11
Why not use yfinance
Im new to this Im not sure lol
If you could provide some code that I can learn from that would be great
ok it seems to occur 3 times
<div class="value svelte-e2k9sg">11</div>
<div class="value svelte-e2k9sg">145</div>
<div class="value svelte-e2k9sg">57.868T</div>
do find all and get the last
tho that still dosent look like what we want but its the closest
Ok thanks
This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.