-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathscrape2.py
More file actions
18 lines (15 loc) · 709 Bytes
/
scrape2.py
File metadata and controls
18 lines (15 loc) · 709 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
from bs4 import BeautifulSoup
from urllib2 import urlopen
BASE_URL = "http://events.newhavenindependent.org/index.php/calendar/by_date/2015/06/07/" #june 7th
def get_today_events(section_url):
html = urlopen(section_url).read()
soup = BeautifulSoup(html, "lxml")
# calendarToday = soup.find("div", "left") <-- see if beautiful soup can find things by id
eventTitles = [h2.string for h2 in soup.findAll("h2", "title")]
eventTimes = [h3.string for h3 in soup.findAll("h3")]
# todays_events = [div.a.string for div in calendarToday.findAll("div")]
return {"eventTitles": eventTitles,
"eventTimes": eventTimes}
if __name__ == '__main__':
events = get_today_events(BASE_URL)
print 'Events: ', events