繁体   English   中英

如何从HTML表创建ical文件

[英]How to create ical files from HTML table

我正在尝试从网站创建可导入的日历事件。 该网站将事件聚集到标准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()获得一个匹配标签的方法,而不是使用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])

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM