ranaroussi / yfinance

Download market data from Yahoo! Finance's API
https://aroussi.com/post/python-yahoo-finance
Apache License 2.0
13.04k stars 2.31k forks source link

Is the package able to extract top gainers via Yahoo API? #154

Open boyac opened 4 years ago

boyac commented 4 years ago

Is the package able to extract top gainers via Yahoo API? Thanks!

CacheMoneyPlaya commented 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

boyac commented 4 years ago

@CacheMoneyPlaya Thanks a million!!

legout commented 4 years ago

You can also use pandas therefore.

import pandas as pd
gainers = pd.read_html('https://finance.yahoo.com/gainers')
drizham commented 1 year ago

is there away of getting top gainers for a specific index? Like DAX or FTSE100 or Nikkei?

IoIxD commented 1 year ago

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
➜  ~
ValueRaider commented 1 year ago

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