Advertisement
Guest User

Untitled

a guest
Sep 18th, 2019
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.96 KB | None | 0 0
  1. import requests
  2. import pandas as pd
  3. import json
  4.  
  5. print ('\n***** Executando programa *****\n')
  6.  
  7. url = 'http://www.fundamentus.com.br/resultado.php'
  8.  
  9. print ('Acessando URL: ', url)
  10.  
  11. myHeaders = {'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36',
  12.     'Referer': 'https://www.nseindia.com', 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8'}
  13.  
  14. html = requests.get(url, headers=myHeaders).content
  15. df_list = pd.read_html(html, decimal= ',', thousands='.')
  16. df = df_list[-1]
  17.  
  18. print ('\nGravando resultado no arquivo XLSX')
  19.  
  20. # Create a Pandas Excel writer using XlsxWriter as the engine.
  21. writer = pd.ExcelWriter('fundamentus.xlsx', engine='xlsxwriter')
  22.  
  23. # Convert the dataframe to an XlsxWriter Excel object.
  24. df.to_excel(writer, sheet_name='Sheet1')
  25.  
  26. # Close the Pandas Excel writer and output the Excel file.
  27. writer.save()
  28.  
  29. print ('\nFinalizando programa')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement