2017-05-24 3 views
0

RSSフィードからデータを収集しようとしています。特定のタグが見つからない

<channel> 
    <title>Events</title> 
    <description>Events</description> 
    <link>https://www.hackerrank.com</link> 
    <item> 
     <title>Codechef - December Lunchtime 2017</title> 
     <description></description> 
     <url>https://www.codechef.com/LTIME55</url> 
     <startTime>2017-12-30 14:00:00 UTC</startTime> 
     <endTime>2017-12-30 17:00:00 UTC</endTime> 
    </item> 
    <item> 
     <title>Codechef - December Cook-Off 2017</title> 
     <description></description> 
     <url>https://www.codechef.com/COOK89</url> 
     <startTime>2017-12-24 16:00:00 UTC</startTime> 
     <endTime>2017-12-24 18:30:00 UTC</endTime> 
    </item> 
    </channel> 
</rss> 

タグのタイトル、開始時刻、終了時刻で要素を見つけようとしています。しかし、私が得る唯一の要素はタイトル要素です。以下のように Pythonのコードは次のとおりです。

soup = BeautifulSoup(plain_text,'html.parser') 
endtime = soup.find_all("endTime") 
print(endtime) 
titles = soup.find_all("title") 
print(titles) 

出力は次のとおりです。

[] 
[<title>....(The required data)....] 
+0

これはHTMLではなくXMLです。これはあなたの出力の理由ではなく、単なる訂正です。 –

+0

私はbeautifullstonesoupを使用する必要がありますか? –

+0

@Vidhyanshujain私の答えを確認 –

答えて

1

BeautifulSoupがあなたのプレーンテキストを解析したら、例えばendtime

を渡し、それは、 lower caseにすべてのタグを変換し、これは
soup.find_all('endtime') 
[<endtime>2017-12-30 17:00:00 UTC</endtime>, 
<endtime>2017-12-24 18:30:00 UTC</endtime>] 
+0

はい私はそれを得た..助けをありがとう –

+0

私は上記の例で渡された方法で '値'を渡す必要がある、私のコードを使用する –

関連する問題