The twelfth annual PyOhio conference was held on July 27-28 and…it. was. awesome!
Now, when it comes to planning for a conference, I must admit that I’m a bit “old school.” A day or two before the gathering, I like to print out the schedule and carefully research each session so that I can choose the ones that best meet my work and personal objectives. Often, a conference will let you download a printable schedule; however, I didn’t find any such file on the PyOhio website. No matter, I can write some Python to scrape the schedule from the website and create my own CSV for printing. Here’s what I did:
Step 1: Import the requisite packages
import requests
from bs4 import BeautifulSoup
import csv
Step 2: Grab the schedule page
result = requests.get('https://www.pyohio.org/2019/events/schedule/')
soup = BeautifulSoup(result.content, 'lxml')
Step 3: Parse out the sessions
Unfortunately, I can only attend Saturday, so my code just focuses on pulling the Saturday sessions:
day_2_list = [['start_end', 'slot1', 'slot2', 'slot3', 'slot4']]
day_2 = soup.select('div.day')[1] # get just Saturday
talks_section = day_2.find('h3', string='Keynotes, Talks, & Tutorials').parent
# iterate across each time block
for time_block in talks_section.select('div.time-block'):
start_end = time_block.find('div', {'class': 'time-wrapper'}).get_text().replace('to', ' - ')
time_rec = [start_end, '', '', '', '']
# now, iterate across each slot within a time block. a time block can have 1-4 time slots
for slot in time_block.select('div.time-block-slots'):
for i, card in enumerate(slot.select('div.schedule-item')):
class_title = card.select_one('h3').get_text()
presenter = (card.select('p')[0]).get_text()
location = (card.select('p')[1]).get_text()
time_rec[i+1] = '{0}\n{1}\n{2}'.format(class_title, presenter, location)
day_2_list.append(time_rec) # after grabbing each slot, write the block to my "day 2" list
Step 4: Write the scraped results to a CSV
csv_file = 'pyohio_20190727_schedule.csv'
with open(csv_file, 'w', newline='') as f:
writer = csv.writer(f)
writer.writerows(day_2_list)
Sweet! Now I can choose just the right sessions to attend. Get my complete code here.
Recent Comments