如何从HTML选项卡创建ical文件

2024-04-25 00:01:51 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试从网站创建可导入的日历事件。 该网站将事件聚集到一个标准的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

Tags: 方法标准网站htmlpagetable事件条目
1条回答
网友
1楼 · 发布于 2024-04-25 00:01:51

我认为您停止使用是因为您使用了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])

相关问题 更多 >