0

BeautifulSoup での HTML 解析について質問があります。私が解析しようとしている Web サイトは次のとおりです

最初に、すべての h3 タグとすべての p タグを取得する関数を作成する必要がありました。私は次のようにしました:

    from bs4 import BeautifulSoup
    import urllib2
    website=urllib2.urlopen("http://www.auc.nl/news-events/events-and-lectures/events-and-lectures.html","r")

    def parseUsingSoup2(content):
        list1=soup.findAll('h3')
        list2=soup.findAll('p')
        return list1+list2        

    parseUsingSoup2(website)

問題の次の部分では、タイムスロット、タイトル、タイプ、および説明の 4 つのタプルを使用して、イベントのリスト (Web サイトには 1 つのイベントしかありません) を要求します。

どうやって始めたらいいのかわからない。私の最初の試みはこれでした:

    def GeneratingListofEvents(content):
        event={}
        list=['time', 'title', 'feature', 'description']
        for item in list: 

ただし、これが正しい方向に向かっているかどうかはわかりません。たとえば、手動で入力せずに HTML ドキュメントから時刻を取得することはできませんでした。前もって感謝します。

4

1 に答える 1

0

必要な情報がすべて含まれていることに注意してください<div class="agendaright">

from bs4 import BeautifulSoup
import urllib2
html = urllib2.urlopen("http://www.auc.nl/news-events/events-and-lectures/events-and-lectures.html","r")
soup = BeautifulSoup(html)

all = soup.find('div',class_="agendaright")
time = all.find('span',class_="event-time").text
# u'18:00 - 20:00'
title = all.h3.text
# u'Images Without Borders Violence, Visuality, and Landscape in Postwar Ambon, Indonesia'
feature = all.find('span',class_="feature").text
# u' | Lecture'
description = all.find('p',class_="event-description").text
# u'This lecture explores the thematization of the visual and expansion of\nits terrain exemplified by the gigantic hijacked billboards with Jesus\nfaces and the painted murals with Christian themes which arose during\nthe ...'

l = [time,title,feature,description]
于 2013-03-31T11:40:34.120 に答える