官术网_书友最值得收藏!

How to do it...

The recipe is implemented in 01/02_events_with_urllib3.py.  The code is the following:

import urllib3
from bs4 import BeautifulSoup

def get_upcoming_events(url):
req = urllib3.PoolManager()
res = req.request('GET', url)

soup = BeautifulSoup(res.data, 'html.parser')

events = soup.find('ul', {'class': 'list-recent-events'}).findAll('li')

for event in events:
event_details = dict()
event_details['name'] = event.find('h3').find("a").text
event_details['location'] = event.find('span', {'class', 'event-location'}).text
event_details['time'] = event.find('time').text
print(event_details)

get_upcoming_events('https://www.python.org/events/python-events/')

The run it with the python interpreter.  You will get identical output to the previous recipe.

主站蜘蛛池模板: 延寿县| 青田县| 赣州市| 集贤县| 高碑店市| 哈巴河县| 罗田县| 综艺| 墨竹工卡县| 吴忠市| 贡嘎县| 西城区| 靖远县| 宜城市| 乐清市| 皮山县| 平顶山市| 南川市| 东辽县| 上高县| 长汀县| 奎屯市| 蕉岭县| 长葛市| 门头沟区| 丰原市| 准格尔旗| 托克托县| 杭锦旗| 策勒县| 玛纳斯县| 广安市| 和林格尔县| 乌兰县| 盐城市| 德庆县| 高唐县| 分宜县| 乐都县| 安泽县| 蒙城县|