Issue
I am trying to retrieve those informations: https://i.stack.imgur.com/uEV1g.png
from this website: https://www.skiinfo.fr/vorarlberg/golm/station-de-ski.html
Below is the code I have so far. I succesfuly find the element on the page, retrieved the name of each element but I cannot find how to retrieve the values (30,50,20,14,44,9.2,44) as there's no identification possible, only the fact that it is between "> <". (Must I say I'm quite new to this!)
link="https://www.skiinfo.fr/vorarlberg/golm/station-de-ski.html"
soup = BeautifulSoup(requests.get(link).content, "html.parser")
div = soup.find('ul', {"class" : "rt_trail circles"})
children = div.findChildren("li" , recursive=False)
for child in children:
print(child.p.string)
which is giving me:
Pistes vertes
Pistes bleues
Pistes rouges
Pistes noires
Pistes
Km pistes
Snowparks
Piste la plus longue
Domaine skiable
Neige de culture
Canons à neige (km pistes)
Could someone explain me what to do ?
Solution
for child in children:
print(child.p.string)
is equivalent to
for child in children:
print(child.find("p").string)
so you are assuming that your values are inside the first p
-tag inside each child
, which is clearly not true. Instead, you can search for the first p
-tag with the css class value
:
for child in children:
print(child.find("p", class_="value").text)
This yields
30%
50%
20%
14
44 km
9.2 km
44 km
Can you go on from here?
Answered By - joni
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.