Skip to content

Instantly share code, notes, and snippets.

@dwillis
Last active April 19, 2017 00:16
Show Gist options
  • Save dwillis/5f39e2ecb8c4694c28294448e677d53b to your computer and use it in GitHub Desktop.
Save dwillis/5f39e2ecb8c4694c28294448e677d53b to your computer and use it in GitHub Desktop.
import csv
import requests
from BeautifulSoup import BeautifulSoup
import time
import datetime
today = str(datetime.date.today().month)+'/'+str(datetime.date.today().day)+'/'+str(datetime.date.today().year)
url = "http://browse.calendar.gwu.edu/EventList.aspx?fromdate=%s&todate=%s&view=DateTime&display=Day&type=public" % (today, today)
response = requests.get(url)
html = response.content
soup = BeautifulSoup(html)
table = soup.find('table', id="tblEvents")
list_of_rows = []
for row in table.findAll('tr')[2:]:
list_of_cells = []
for cell in row.findAll('td'):
list_of_cells.append(cell.text.encode('utf-8'))
list_of_rows.append(list_of_cells)
outfile = open("events2.csv", "wb")
writer = csv.writer(outfile)
writer.writerow(["time", "url", "text"])
writer.writerows(list_of_rows)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment