Skip to content

Instantly share code, notes, and snippets.

@shashankvemuri
Last active May 25, 2020 03:35
Show Gist options
  • Save shashankvemuri/e738cb319c0466f39892daec34259cae to your computer and use it in GitHub Desktop.
Save shashankvemuri/e738cb319c0466f39892daec34259cae to your computer and use it in GitHub Desktop.
get data from finviz
# Get Data
finviz_url = 'https://finviz.com/quote.ashx?t='
news_tables = {}
for ticker in tickers:
url = finviz_url + ticker
req = Request(url=url,headers={'user-agent': 'my-app/0.0.1'})
resp = urlopen(req)
html = BeautifulSoup(resp, features="lxml")
news_table = html.find(id='news-table')
news_tables[ticker] = news_table
try:
for ticker in tickers:
df = news_tables[ticker]
df_tr = df.findAll('tr')
print ('\n')
print ('Recent News Headlines for {}: '.format(ticker))
for i, table_row in enumerate(df_tr):
a_text = table_row.a.text
td_text = table_row.td.text
td_text = td_text.strip()
print(a_text,'(',td_text,')')
if i == n-1:
break
except KeyError:
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment