Quantcast
Channel: Active questions tagged selenium - Stack Overflow
Viewing all articles
Browse latest Browse all 97778

Get Elements Between 2 Elements With Soup

$
0
0

I have the following HTML code :

<div class="info">
    <div class="left-wrap"><span class="date">DATE-1</span></div>
</div>

<div class="clients-list">
        <div>
            <span class="client">client1</span>
            <span class="client">client2</span>
            <span class="client">client3</span>
        </div>
    </div>

<div class="info">
    <div class="left-wrap"><span class="date">DATE-2</span></div>
</div>
<div class="clients-list">
        <div>
            <span class="client">client4</span>
            <span class="client">client5</span>
        </div>
</div>

I want to get data related to each date , I did the following :

date = []
clients = []
for item in soup.find_all(class_='date'):
    date.append(item.get_text().strip())
for item in soup.find_all(class_='client'): 
    clients.append(item.get_text().strip())
print date
print clients

I end up with list of dates , containing "date1" and "date2", and list of clients containing clients1 to clients5.

My problem is that I cannot map clients with date , for example client1,client2 and client3 and related to date1, but I didn't find anyway to know how many clients will be under each date.


Viewing all articles
Browse latest Browse all 97778

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>