Last active
January 31, 2018 17:20
-
-
Save juanifioren/c2f6741a051b8b114e07bf9cb6f94ef0 to your computer and use it in GitHub Desktop.
Get stock news by symbol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cssselect | |
from lxml import html | |
import requests | |
def get_stock_news(symbol): | |
url = 'https://www.bloomberg.com/quote/{symbol}:US' | |
r = requests.get(url.format(symbol=symbol)) | |
tree = html.fromstring(r.content) | |
articles = [] | |
for element in tree.cssselect('div.news__state[data-group="company-news"] article'): | |
article = {} | |
article['date'] = element.cssselect('time')[0].text | |
article['link'] = element.cssselect('a')[0].get('href') | |
article['title'] = element.cssselect('a')[0].text | |
articles.append(article) | |
return articles | |
print get_stock_news('GOOGL') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment