Skip to content

Instantly share code, notes, and snippets.

Avatar

Pratap Vardhan pratapvardhan

View GitHub Profile
@pratapvardhan
pratapvardhan / GFinSectorIndustryBasic.py
Created Jun 5, 2014
Python Script to extract Sector and Industry for a company stock listed on Google Finance
View GFinSectorIndustryBasic.py
from urllib import urlopen
from lxml.html import parse
'''
Returns a tuple (Sector, Indistry)
Usage: GFinSectorIndustry('IBM')
'''
def GFinSectorIndustry(name):
tree = parse(urlopen('http://www.google.com/finance?&q='+name))
return tree.xpath("//a[@id='sector']")[0].text, tree.xpath("//a[@id='sector']")[0].getnext().text