Reputation: 327
from requests import get
from bs4 import BeautifulSoup
url = 'https://www.ceda.com.au/Events/Upcoming-events'
response = get(url)
events_container = html_soup.find_all('div', class_ = 'list-bx')
event1name = events_container[0]
print(event1name.a.text)
Eventdate = html_soup.find('div', class_ = ' col-md-4 col-sm-4 side-box well
side-boxTop')
x = Eventdate.div.text
print(x)
I'm trying to print the second span class on the class " col-md-4 col-sm-4 side-box well side-boxTop" But I coud'nt able to print the second span class (Second P tag (Event Date) from the class as there is no unique span name for the each span class
Upvotes: 1
Views: 871
Reputation: 1759
from requests import get
from bs4 import BeautifulSoup
url = 'https://www.ceda.com.au/Events/Upcoming-events'
response = get(url)
html_soup=BeautifulSoup(response.content,"lxml")
events_container = html_soup.find_all('div', class_ = 'list-bx')
event1name = events_container[0]
print(event1name.a.text)
Eventdate = html_soup.find('div', class_ = ' col-md-4 col-sm-4 side-box well side-boxTop')
date=Eventdate.find_all("p")[1].text
print(date)
You can apply find_all to parent as well so you can just use find_all and navigate to any node you want.
Now you can just edit your date by textManipulation or so.
Upvotes: 1
Reputation: 22440
Try this. It will fetch you the date you are after:
from requests import get
from bs4 import BeautifulSoup
res = get('https://www.ceda.com.au/Events/Upcoming-events')
soup = BeautifulSoup(res.text,"lxml")
item_date = '\n'.join([' '.join(item.find_parent().select("span")[0].text.split()) for item in soup.select(".side-list .icon-calendar")])
print(item_date)
Partial output:
24/01/2018
30/01/2018
31/01/2018
31/01/2018
Upvotes: 1