mercredi 9 mai 2018

Scraping days and months from a website using BeautifulSoup

I am to scrap all dates and month of some events from a given website.
There is a special class (for example let's look how days are written):

<span class="date-day">28</span>

My code looks like this:

from bs4 import BeautifulSoup   
soup_2 = BeautifulSoup(r.content, 'html.parser')
temp_1 = soup_2.find_all('span', class_ = 'date-day')
event_day = []
for a in temp_1:
    event_day.append(a['date-day'])

However there is a KeyError which I guess mean that something is wrong with event_day.append(a['date-day']) this part.
How should the proper key look like?
And what is the key for months?


There is a similar post here but the solution completely doesn't match my problem (or maybe my code is wrong but similar way worked with scraping links and for some alternative texts).




Aucun commentaire:

Enregistrer un commentaire