- Python Web Scraping Cookbook
- Michael Heydt
- 77字
- 2021-06-30 18:43:57
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.
推薦閱讀
- 黑客攻防實(shí)戰(zhàn)技術(shù)完全手冊(cè):掃描、嗅探、入侵與防御
- 物聯(lián)網(wǎng)網(wǎng)絡(luò)安全及應(yīng)用
- Spring Boot 2.0 Projects
- 網(wǎng)絡(luò)創(chuàng)新指數(shù)研究
- 信息通信網(wǎng)絡(luò)建設(shè)安全管理概要2
- 通信十年:擁抱互聯(lián)網(wǎng)
- Learning Windows 8 Game Development
- 大型企業(yè)微服務(wù)架構(gòu)實(shí)踐與運(yùn)營(yíng)
- Dart Cookbook
- Python API Development Fundamentals
- 新媒體交互藝術(shù)
- 智能物聯(lián)網(wǎng):區(qū)塊鏈與霧計(jì)算融合應(yīng)用詳解
- Corona SDK Application Design
- 網(wǎng)絡(luò)互聯(lián)技術(shù)(理論篇)
- Twilio Cookbook(Second Edition)