Xpath class id + text

147 Views Asked by At

I am trying to scrape permissions tables in the following site: https://register.fca.org.uk/ShPo_FirmDetailsPage?id=001b000000MfaDiAAJ

I am tryinng to find out if xpath is capable of locating a specific class with a text afterwards such as this (Please note ID are random so cannot locate using them, and also classes are the same for each table)

Advising on a home purchase plan

                    <div id="a2Nb000000035ohEAA" class="collapse DisciplineDetails PassportDetails PermDesc">
                      <h3 class="PermissionsListHeader">Advising on a home purchase plan</h3>
                      <br>
                      <br>
                    </div>

                    <ul class="PermissionConditionsList">
                      <li class="PermissionsConditionsItem">
                        Customer Type 

                        <ul class="PermCondsLimitationsList">
                          <li style="list-style: none"><span id="j_id0:j_id1:j_id110:regActTable:0:j_id531:0:j_id533:0:j_id535:0:j_id538"></span></li>

                          <li class="PermCondsLimitationsItem Popover">Customer</li>
                        </ul>
                      </li>
                    </ul>

                    <ul class="PermissionConditionsList">
                      <li class="PermissionsConditionsItem">
                        Investment Type 

                        <ul class="PermCondsLimitationsList">
                          <li style="list-style: none"><span id="j_id0:j_id1:j_id110:regActTable:0:j_id531:1:j_id533:0:j_id535:0:j_id538"></span></li>

                          <li class="PermCondsLimitationsItem Popover">Home purchase plans</li>
                        </ul>
                      </li>
                    </ul>
                  </div>
2

There are 2 best solutions below

0
Aleksandr On BEST ANSWER

Still, it is hard to understand what you want to achieve.. As far as I understand, you need to parse PermCondsLimitationsItem Popover class value(s) (in this case Customer) based on whether the PermissionsListHeader class attribute value equals "Advising on a home purchase plan". If so, then save value of PermCondsLimitationsItem Popover class attribute.

So the following logic should do the thing.

  1. Parse the < h3 > and test the initial condition:

    //h3[@class='PermissionsListHeader']//text()

  2. If the attribute value equals "Advising on a home purchase plan" parse PermCondsLimitationsItem Popover class.

    //li[@class='PermCondsLimitationsItem Popover']//text()

If the condition is not satisfied, just put the blank space etc.

0
maheeka On

If you want to get the class of the element containing a particular text you can use the following xpath :

//h3[text()='Advising on a home purchase plan']/@class

If you need to get the whole div, use :

//div[text()='Advising on a home purchase plan']

Your requirement is not clear. If this is not what you are looking for , please explain more with the expected output.