1

I am using Selenium and python to extract table from HTML but I am able to extract only first table. I want to extract second table also I am new t selenium.

Html code

<div class="fondo-top">
        <h3>Flood Forecasted Site</h3>
        <div class="editorwys">



        <h4>Site Name : Araria</h4> 
                <table style="width: 100%">
                    <tbody><tr>
                        <th style="width: 25%"><strong>District Name:</strong></th>
                        <td style="width: 25%"><strong>Araria</strong></td>

                            <th style="width: 25%"><strong>Warning Level (WL):</strong></th>
                            <td style="width: 25%"><strong> Meters (m)</strong></td>

                    </tr>
                    <tr>
                        <th><strong>River Name:</strong></th>
                        <td><strong>Mahananda</strong></td>

                            <th><strong>Danger Level (DL):</strong></th>
                            <td><strong> Meters (m)</strong></td>

                    </tr>
                    <tr>
                        <th><strong>Basin Name:</strong></th>
                        <td><strong>GANGA<strong></strong></strong></td>

                        <th><strong>Highest Flood Level (HFL):</strong></th>
                        <td><strong>49.4 Meters (m)<strong></strong></strong></td>

                    </tr>
                    <tr>
                        <th><strong>Division Name:</strong></th>

                        <td><a target="_blank" href="/opencms/opencms/ffs/Detail?code=029-mgd4ptn " onclick="window.open(this.href, this.target, 'width=1000, height=600, toolbar=no, resizable=no'); return false;">Lower Ganga Division-I(LGD-I), Patna</a></td>

                        <th><strong>HFL Attained date:</strong></th>
                        <td>14-08-2017</td>

                    </tr>
                </tbody></table>
                <p>&nbsp;</p>
                <table>
                    <tbody><tr>
                        <th colspan="3" style="text-align: center;"><strong>PRESENT WATER LEVEL</strong></th>
                    </tr>

                    <tr>                            

                        <td class="" style="width:33%; height:18px;">Date: 22-06-2018 08:00</td>
                        <td class="" style="width:33%;">Value: 45.34 Meters (m)</td>
                        <td class="" style="width:33%;">Trend: Steady</td>
                    </tr>
                    <tr>
                        <th colspan="3" style="text-align: center;"><strong>CUMULATIVE DAILY RAINFALL</strong></th>
                    </tr>
                    <tr>

                            <td style="width:33%; height:18px;">Date: 22-06-2018 08:30</td>
                            <td style="width:33%;">Value: 5.0 Milimiters (mm)</td>
                            <td style="width:33%;"></td>

                    </tr>
                </tbody></table>                            
                    <p>&nbsp;</p>                       



                                <table style="width: 100%">
                                    <tbody><tr>
                                        <th colspan="4" style="text-align: center;"><strong>NO FLOOD FORECAST</strong></th>
                                    </tr>
                                </tbody></table>



            <div class="botonera">

                <a href="/ffs/data-flow-list-based/" class="mas-info"> Go Back</a>

            </div>
    </div>
</div>

I am using driver.find_element_by_css_selector('table > tbody').text to extract the first table. Now how to extract the second and third table table??? I will realy appriciate any help in this regard

1 Answer 1

2

you can use find_elements_by_css_selector to find multiple elements (these methods will return a list) with all tables founded , instead of what you are doing with one element find_element_by_css_selector, try this

for form_body in driver.find_elements_by_css_selector('table > tbody'):
    print(form_body.text)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.