Solution 1 :

I’m using BeautifulSoup to parse the HTML you provided.

Then I navigate the soup using the spans. After I have the target element, I get the text of the element.



This finds all spans and selects the second one.


I have this additional code before calling either of those.

from bs4 import BeautifulSoup

html = "<span class="posting-location go-to-posting">Santa Gertrudes , <span> Tatuapé, São Paulo</span></span>"

soup = BeautifulSoup(html, 'html.parser')

Problem :

I have the following html piece

    soup = <span class="posting-location go-to-posting">
                                Santa Gertrudes , 
                                <span> Tatuapé, São Paulo</span>

I know that, to access the “Tatuapé, São Paulo”, I can use


However, how do I select “Santa Gertrudes , “?


Comment posted by Jacob Evans

I’ve been trying to figure this out for weeks, you just saved my job! I’ll probably hold off until Friday to implement.

Comment posted by Johnathan Irvin

@JacobEvans I’m glad you found this useful!


Leave a Reply

Your email address will not be published. Required fields are marked *