Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from lxml import html
- import requests
- import xlwt
- page_IBM = requests.get('http://www.google.com/finance?q=IBM&ei=XL2zVtn6E42amAGu6pzADQ')
- tree = html.fromstring(page_IBM.content)
- PAGE_Alcoa=requests.get('http://www.google.com/finance?q=alcoa&ei=08-zVqGeKsfEmAGFu62YAg')
- Page_Alcoa_EarnigsGrowth=requests.get('http://www.nasdaq.com/symbol/aa/earnings-growth')
- Page_Alcoa_PEG_Ratio=requests.get('http://www.nasdaq.com/symbol/aa/peg-ratio')
- tree_Alcoa = html.fromstring(PAGE_Alcoa.content)
- tree_Alcoa_Growth=html.fromstring(Page_Alcoa_EarnigsGrowth.content)
- tree_Alcoa_PEG_RATIO=html.fromstring(Page_Alcoa_PEG_Ratio.content)
- #This will create a list of buyers:
- IBM = tree.xpath('//span[@id="ref_18241_l"]/text()')
- #This will create a list of prices
- Change_IBM = tree.xpath('//span[@id="ref_18241_c"]/text()')
- Alcoa=tree_Alcoa.xpath('//span[@id="ref_803_l"]/text()')
- Change_Alcoa=tree_Alcoa.xpath('//span[@id="ref_803_c"]/text()')
- Growth_Alcoa=tree_Alcoa_Growth.xpath('//span[@id="quotes_content_left_textinfo"]/text()')
- PEG_RATIO_ALCOA=tree_Alcoa_PEG_RATIO.xpath('//class[@id="marginL5px marginR20p"]/text()')
- print ('IBM Stock Price(Source: Google Finance)', IBM)
- #print ('Change IBM since last refresh(Source: Google Finance)',Change_IBM)
- print ('Change Alcoa since last refresh(Source: Google Finance)',Change_Alcoa)
- print ('Growth prediction Alcoa (Source Nasdaq:)',Growth_Alcoa)
- print ('PEG Ratio Alcoa (Source Nasdaq:)',Growth_Alcoa)
- DATA = (("IBM",),("Stock Price", IBM,),
- ("Change since Last Refresh", Change_IBM,),
- (" "),
- ("Alcoa",),
- ("Stock Price", Alcoa,),
- ("Change since Last Refresh", Change_Alcoa,),
- ("Growth_Alcoa", Growth_Alcoa,),
- ("PEG Ratio", PEG_RATIO_ALCOA,),)
- wb = xlwt.Workbook()
- ws = wb.add_sheet("My Sheet")
- for i, row in enumerate(DATA):
- for j, col in enumerate(row):
- ws.write(i, j, col)
- ws.col(0).width = 256 * max([len(row[0]) for row in DATA])
- wb.save("myworkbook.xls")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement