mercredi 26 avril 2017

Getting data from this table html python

I would like to extract data from this table which shows the currency rates.

Visit http://ift.tt/2q7cL0U

I have tried this approach but its not working

      table_id = driver.find_element(By.ID, 
     'data_configuration_feeds_ct_fields_body0')
      rows = table_id.find_elements(By.TAG_NAME, "tr") # get all of the 
      rows in the table
      for row in rows:

      col = row.find_elements(By.TAG_NAME, "td")[1] #note: index start from 
      0, 1 is col 2
      print(col.text) #prints text from the element

This is the html

    </td>

                    <td valign="top" class="OuterProdCell test">

                                <table class="ProductCell">
                                    <tr>
                                    <td class="rateCountryFlag">
                                        <ul id="prodImages">
                                            <li>
                                                <a href="/travel-money/buy-chilean-peso" title="Buy Chilean Peso" class="flags chilean-peso" ></a>
                                            </li>
                                        </ul>
                                    </td>

                                    <td class="ratesName">
                                    <a href="/travel-money/buy-chilean-peso" title="Buy Chilean Peso">
                                    Chilean Peso</a>
                                    </td>

                                    <td class="ratesClass">
                                    <a  class="orderText" href="/travel-money/buy-chilean-peso" title="Buy Chilean Peso">774.8540</a>
                                    </td>
                                    <td class="orderNow">                                           
                                        <ul id="prodImages">
                                            <li>
                                                <a class="reserveNow" href="/travel-money/buy-chilean-peso" title="Buy Chilean Peso">Order<br/>now</a>
                                            </li>
                                            <li>
                                                <a href="/travel-money/buy-chilean-peso" title="Buy Chilean Peso" class="flags arrowGreen" ></a>
                                            </li>
                                        </ul>
                                    </td>
                                    </tr>
                                </table>

I have also tried the python selenium approach however I can get the currency rate of each one but not the name

             driver.get("http://ift.tt/2qelvPi
             rates")
             rates = driver.find_elements_by_class_name("ratesClass")

             for rate in rates:
             print(rate.text)




Aucun commentaire:

Enregistrer un commentaire