-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
executable file
·28 lines (23 loc) · 890 Bytes
/
main.py
File metadata and controls
executable file
·28 lines (23 loc) · 890 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#!/usr/bin/env python3
import requests
from bs4 import BeautifulSoup
import csv
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36'}
data = []
scrapesite = '' # Enter url to scrape
if __name__ == '__main__':
print("Scraper started")
page = requests.get(scapesite, headers=headers)
soup = BeautifulSoup(page.text, 'html5lib')
table = soup.find('table', attrs={'class':'dataTable'})
table_body = table.find('tbody')
rows = table_body.find_all('tr')
for row in rows:
cols = row.find_all('td')
cols = [ele.text.strip() for ele in cols]
data.append([ele for ele in cols]) # Get rid of empty values
print(data)
with open('output.csv', 'w') as myfile:
wr = csv.writer(myfile, quoting=csv.QUOTE_ALL)
for x in data:
wr.writerow(x)