Skip to content Skip to sidebar Skip to footer

How To Get Only First Class' Data Between Two Same Classes

On https://www.hltv.org/matches page, matches divided by dates but the classes are same. I mean, This is today's match class
find(), which return the first match found.

Using this will give you what you want:

today = soup.find('div', class_='match-day')

But, if you want to explicitly specify the date, you can find the tag containing today's date, by using text='2018-05-02' as a parameter for the find() method. But, note that in the page source, the tag is <span class="standard-headline">2018-05-02</span> and not a <div> tag. After getting this tag, use .parent to get the <div class="match-day"> tag.

today = soup.find('span', text='2018-05-02').parent

Again, if you want to make the solution more generic, you can use datetime.date.today() instead of the hard-coded date.

today = soup.find('span', text=datetime.date.today()).parent

You'll have to import the datetime module for this.


Post a Comment for "How To Get Only First Class' Data Between Two Same Classes"