Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import csv
- from pprint import pprint
- from bs4 import BeautifulSoup
- import requests
- url = "http://www.nse.com.ng/Issuers-section/corporate-disclosures/corporate-actions/closure-of-register"
- soup = BeautifulSoup(requests.get(url).content, "html.parser")
- rows = soup.select("table.ms-rteTable-default tr")
- headers = [header.get_text(strip=True).encode("utf-8") for header in rows[0].find_all("td")]
- data = [dict(zip(headers, [cell.get_text(strip=True).encode("utf-8") for cell in row.find_all("td")]))
- for row in rows[1:]]
- # see what the data looks like at this point
- pprint(data)
- with open('sara.csv', 'wb') as csvfile:
- spamwriter = csv.DictWriter(csvfile, headers, delimiter='\t', quotechar="\n")
- for row in data:
- spamwriter.writerow(row)
- output:
- Traceback (most recent call last):
- File "/home/martin/dev/python/england.py", line 11, in <module>
- headers = [header.get_text(strip=True).encode("utf-8") for header in rows[0].find_all("td")]
- IndexError: list index out of range
- [Finished in 0.709s]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement