Skip to content

Instantly share code, notes, and snippets.

@pratapvardhan
Created June 5, 2014 09:56
Show Gist options
  • Save pratapvardhan/9b57634d57f21cf3874c to your computer and use it in GitHub Desktop.
Save pratapvardhan/9b57634d57f21cf3874c to your computer and use it in GitHub Desktop.
Python Script to extract Sector and Industry for a company stock listed on Google Finance
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
@vadik10224
Copy link

vadik10224 commented Nov 29, 2020

Hello.
Go to web page. On MS Window's browser (Chrome). Mous right click on desireble element in web page and then "Inspect" => browser showd HTML script and selects element that you have clicked. Right click on selected item and chose simple XPath.
I recomend to find in google tutorial of XPath

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment