-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstockTracker.py
50 lines (48 loc) · 1.52 KB
/
stockTracker.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import requests
from bs4 import BeautifulSoup
import pandas as pd
yahoo = "https://finance.yahoo.com/most-active"
html = requests.get(yahoo)
data = html.text
soup = BeautifulSoup(data,'lxml')
codes =[]
names=[]
prices=[]
changes=[]
percentage_changes=[]
total_volumes=[]
market_caps=[]
price_earning_ratios=[]
#GETTING THE TABLE FROM YAHOO FINANACE
table =soup.find("tbody")
for listing in table.find_all("tr"):
code =listing.find('td',attrs= {'aria-label':'Symbol'})
codes.append(code.text)
name = listing.find('td',attrs={"aria-label":"Name"})
names.append(name.text)
price = listing.find('td',attrs={'aria-label':"Price (Intraday)"})
prices.append(price.text)
# change =listing.find('tr',attrs={'aria-label':"Change"})
# changes.append(change.text)
# percentage_change= listing.find('tr',attrs={"aria-label":"% Change"})
# percentage_changes.append(percentage_change.text)
# total_volume = listing.find("tr",attrs={"aria-label":"Volume"})
# total_volumes.append(total_volume.text)
# marketcap = listing.find("tr",attrs={'aria-label':"Market Cap"})
# market_caps.append(marketcap.text)
# price_earning_ratio = listing.find('tr',attrs={"aria-label":"PE Ratio (TTM)"})
# price_earning_ratios.append(price_earning_ratio.text)
# print (codes)
# print(names)
# print(prices)
# print(changes)
# print(percentage_changes)
# print(total_volumes)
# print(market_caps)
# print(price_earning_ratios)
df = pd.DataFrame({
"Symbols": codes,
"Names": names,
"Prices": prices
})
print(df)