python - 如何从 HTML 表创建 ical 文件
问题描述
我正在尝试从网站创建可导入的日历事件。该网站将事件聚集到一个标准的 html 表中。
我想知道 beautfulsoup 是否是解决这个问题的正确方法,因为我只得到第一个条目,然后什么也没有。
quote_page = "http://www.ellen-hartmann.de/babybasare.html"
page = urllib2.urlopen(quote_page)
soup = BeautifulSoup(page, "html.parser")
table = soup.find("table", {"border": "1"})
td = table.find("td", text="Veranstaltungstyp ")
print table
td_next = table.find_next("tr")
print td_next
解决方案
我认为您正在停止使用,因为您使用find()
which 获得一个匹配的标签,而不是find_all()
获得所有匹配的标签。然后你必须遍历结果
import requests
from bs4 import BeautifulSoup
response = requests.get("http://www.ellen-hartmann.de/babybasare.html")
soup = BeautifulSoup(response.text, 'html.parser')
# now let's find every row in every table
for row in soup.find_all("tr"):
# grab the cells within the row
cells = row.find_all("td")
# print the value of the cells as a list. This is the point where
# you will need to filter the rows to figure out what is an event (and
# what is not), determine the start date and time, and convert the values
# to iCal format.
print([c.text for c in cells])
推荐阅读
- python - websocket在接收数据时是否会花费出站数据流量?
- python - RuntimeError:当前 NumPy 安装未能通过健全性检查
- sql - SSRS 报告垂直对齐更改为水平
- kubernetes - Kubernetes spec.ports required value 错误
- adonis.js - AdonisJs 找不到模块 'phc-bcrypt'
- python-3.x - 使用子进程立即退出 shell 脚本
- c++ - Can I use lambda as a hashing function in boost::multi_index hash-like interface?
- javascript - 如何使我的不和谐机器人具有自定义状态(discord.js)
- python - Python底图:将图例高度调整为地图区域
- java - 多级 @JsonTypeInfo 和 @JsonSubTypes