首先,安装先决条件:
pip install beautifulsoup4
pip install requests
pip install lxml
swr3.py:强>
import requests, lxml
from bs4 import BeautifulSoup
parsedsongs = []
result = requests.get('http://www.swr3.de//-/id=47424/cf=42/did=65794/93avs/index.html?hour=5&date=2015-10-23')
soup = BeautifulSoup(result.content, "lxml")
detailbodys = soup.find_all('div', 'detail-body')
for detailbody in detailbodys:
title = detailbody.h4.string.encode('utf-8').strip()
if detailbody.h5:
artist = detailbody.h5.string.encode('utf-8').strip()
else:
artist = detailbody.span.string.encode('utf-8').strip()
parsedsongs.append({'artist': artist, 'title': title})
for entry in parsed