How to do it...

The script for this recipe is 01/04_events_with_selenium.py.

  1. The following is the code:
from selenium import webdriverdef get_upcoming_events(url):    driver = webdriver.Firefox()    driver.get(url)    events = driver.find_elements_by_xpath('//ul[contains(@class, "list-recent-events")]/li')    for event in events:        event_details = dict()        event_details['name'] = event.find_element_by_xpath('h3[@class="event-title"]/a').text        event_details['location'] = event.find_element_by_xpath('p/span[@class="event-location"]').text        event_details['time'] = event.find_element_by_xpath('p/time').text        print(event_details)    driver.close()get_upcoming_events('https://www.python.org/events/python-events/')
  1. And run the script with Python.  You will see familiar ...

Get Python Web Scraping Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.