Open boyac opened 4 years ago
just use beautiful soup:
url = "https://finance.yahoo.com/gainers"
soup = BeautifulSoup(requests.get(url).text, 'html.parser')
assets = soup.find_all('a', attrs={"class":"Fw(600)"})
This gets top 5 performers of the day
@CacheMoneyPlaya Thanks a million!!
You can also use pandas therefore.
import pandas as pd
gainers = pd.read_html('https://finance.yahoo.com/gainers')
is there away of getting top gainers for a specific index? Like DAX or FTSE100 or Nikkei?
This is an awful solution. The page will give you a 404 if you don't have a user agent set, and even if you do, the resulting page is ginormous because yahoo craps their site to the brim with useless shit.
curl -A "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36" https://finance.yahoo.com/gainers -o lol
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 1909k 0 1909k 0 0 1517k 0 --:--:-- 0:00:01 --:--:-- 1517k
➜ ~ du lol -h
1.9M lol
➜ ~
yahooquery
code has references to "gainers", maybe look into that (yahooquery
uses API instead of scraping = faster). If you're interested in porting to yfinance, post in #1546
Is the package able to extract top gainers via Yahoo API? Thanks!