Advertisement
Guest User

Untitled

a guest
Feb 8th, 2016
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.93 KB | None | 0 0
  1. from lxml import html
  2. import requests
  3. import xlwt
  4. page_IBM = requests.get('http://www.google.com/finance?q=IBM&ei=XL2zVtn6E42amAGu6pzADQ')
  5. tree = html.fromstring(page_IBM.content)
  6. PAGE_Alcoa=requests.get('http://www.google.com/finance?q=alcoa&ei=08-zVqGeKsfEmAGFu62YAg')
  7. Page_Alcoa_EarnigsGrowth=requests.get('http://www.nasdaq.com/symbol/aa/earnings-growth')
  8. Page_Alcoa_PEG_Ratio=requests.get('http://www.nasdaq.com/symbol/aa/peg-ratio')
  9. tree_Alcoa = html.fromstring(PAGE_Alcoa.content)
  10. tree_Alcoa_Growth=html.fromstring(Page_Alcoa_EarnigsGrowth.content)
  11. tree_Alcoa_PEG_RATIO=html.fromstring(Page_Alcoa_PEG_Ratio.content)
  12. #This will create a list of buyers:
  13. IBM = tree.xpath('//span[@id="ref_18241_l"]/text()')
  14. #This will create a list of prices
  15. Change_IBM = tree.xpath('//span[@id="ref_18241_c"]/text()')
  16.  
  17. Alcoa=tree_Alcoa.xpath('//span[@id="ref_803_l"]/text()')
  18. Change_Alcoa=tree_Alcoa.xpath('//span[@id="ref_803_c"]/text()')
  19. Growth_Alcoa=tree_Alcoa_Growth.xpath('//span[@id="quotes_content_left_textinfo"]/text()')
  20. PEG_RATIO_ALCOA=tree_Alcoa_PEG_RATIO.xpath('//class[@id="marginL5px marginR20p"]/text()')
  21. print ('IBM Stock Price(Source: Google Finance)', IBM)
  22. #print ('Change IBM since last refresh(Source: Google Finance)',Change_IBM)
  23.  
  24.  
  25.  
  26.  
  27. print ('Change Alcoa since last refresh(Source: Google Finance)',Change_Alcoa)
  28. print ('Growth prediction Alcoa (Source Nasdaq:)',Growth_Alcoa)
  29. print ('PEG Ratio Alcoa (Source Nasdaq:)',Growth_Alcoa)
  30.  
  31. DATA = (("IBM",),("Stock Price", IBM,),
  32. ("Change since Last Refresh", Change_IBM,),
  33. (" "),
  34. ("Alcoa",),
  35. ("Stock Price", Alcoa,),
  36. ("Change since Last Refresh", Change_Alcoa,),
  37. ("Growth_Alcoa", Growth_Alcoa,),
  38. ("PEG Ratio", PEG_RATIO_ALCOA,),)
  39.  
  40.  
  41. wb = xlwt.Workbook()
  42. ws = wb.add_sheet("My Sheet")
  43. for i, row in enumerate(DATA):
  44. for j, col in enumerate(row):
  45. ws.write(i, j, col)
  46. ws.col(0).width = 256 * max([len(row[0]) for row in DATA])
  47. wb.save("myworkbook.xls")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement