Skip to content

Instantly share code, notes, and snippets.

@juanifioren
Last active January 31, 2018 17:20
Show Gist options
  • Save juanifioren/c2f6741a051b8b114e07bf9cb6f94ef0 to your computer and use it in GitHub Desktop.
Save juanifioren/c2f6741a051b8b114e07bf9cb6f94ef0 to your computer and use it in GitHub Desktop.
Get stock news by symbol
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