I try to extract the "1 min" from the HTML code below using BeautifulSoup
<ul class="date-list infos">
<li>
<div class="date-list--time">1 min</div>
<div class="date-list--extras"></div>
</li>
<li>
<div class="date-list--time">30 min</div>
<div class="date-list--extras"></div>
</li>
</ul>
For this, I write the code below in Python:
# import libraries
import urllib2
from bs4 import BeautifulSoup
# specify the url
quote_page = 'http://beta.stm.info/fr/infos/reseaux/bus/reseau-local/ligne-51-est/56184'
page = urllib2.urlopen(quote_page)
# parse the html using beautiful soup and store in variable `soup`
soup = BeautifulSoup(page, 'html.parser')
# EXTRACT FIELD 1
name_titre = soup.find('div', attrs={'class': 'label not-accessible'})
name_t = name_titre.text.strip()
print name_t
# EXTRACT FIELD 2
time_passage = soup.find('div', attrs={'class': "date-list--time"})
t_passage = time_passage
print t_passage
It worked well for other data I wanted to extract (EXTRACT 1), but here I just get "None" as a print output for EXTRACT 2.
Could please someone tell me what I am doing wrong? I guess the issue is that the HTML includes a list of items for EXTRACT 2, but not sure...
Thanks!