Advertisement
tosip

DataScrap

Sep 5th, 2021
248
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.85 KB | None | 0 0
  1. import pandas as pd
  2. import requests
  3. from bs4 import BeautifulSoup
  4. import csv
  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','wb')
  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.  
  27. result = pd.DataFrame(data, columns=['#', 'DATE', 'TRADING CODE', 'LTP*', 'HIGH', 'LOW', 'OPENP*', 'CLOSEP*', 'YCP', 'TRADE', 'VALUE (mn)', 'VOLUME'])
  28.  
  29. print(result)
  30.  
  31. file.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement