如何从 HTML table 创建 ical 文件

How to create ical files from HTML table

我正在尝试从网站创建重要的table 日历事件。 该网站将事件聚集成一个标准 html table.

我想知道 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() 获得了一个匹配的标签,而不是 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])