Advertisement
mdgaziur001

Help thing :) (2)

Sep 5th, 2021
1,241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.89 KB | None | 0 0
  1. import requests
  2. from bs4 import BeautifulSoup
  3. import csv
  4. import pandas as pd
  5.  
  6. url = 'https://www.dse.com.bd/day_end_archive.php?startDate=2019-09-05&endDate=2021-09-05&inst=All%20Instrument&archive=data#'
  7.  
  8. r = requests.get(url)
  9. html = r.text
  10.  
  11. soup = BeautifulSoup(html)
  12. table = soup.find('table', {"class": "table table-bordered background-white shares-table fixedHeader"})
  13. rows = table.find_all('tr')
  14. data = []
  15.  
  16. file = open('dsedata.csv','w')
  17. writer = csv.writer(file)
  18.  
  19. #write header rows
  20. #writer.writerow(data)
  21.  
  22. for row in rows[1:]:
  23.     cols = row.find_all('td')
  24.     cols = [ele.text.strip() for ele in cols]
  25.     data.append([ele for ele in cols if ele])
  26.     writer.writerow(data[-1])
  27.  
  28. result = pd.DataFrame(data, columns=['#', 'DATE', 'TRADING CODE', 'LTP*', 'HIGH', 'LOW', 'OPENP*', 'CLOSEP*', 'YCP', 'TRADE', 'VALUE (mn)', 'VOLUME'])
  29.  
  30. print(result)
  31.  
  32. file.close()
  33.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement