Vidhyanshu jain
Vidhyanshu jain

Reputation: 341

Beautifulsoup not finding certain tags

I am trying to collect some data from an rss feed I have its link whose htmls goes somewhat like this.

 <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>

I am trying to find elements by tags title, start time and end time. But the only elements i get are the title elements. The python code is as followed:

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

The output is:

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

Upvotes: 0

Views: 126

Answers (1)

akash karothiya
akash karothiya

Reputation: 5950

This is because, once BeautifulSoup parse your plain text, it converts all tags to lower case, for example pass endtime

soup.find_all('endtime')
[<endtime>2017-12-30 17:00:00 UTC</endtime>,
 <endtime>2017-12-24 18:30:00 UTC</endtime>]

Upvotes: 1

Related Questions