简体   繁体   中英

How Do I Extract a link of a button that is defined using a class within a '<p>' tag in html using selenium

I have been trying to web-scrape a website that does not offer API's and I have ran into a problem where I want the link of a button but the button is not defined using the traditional button or input tags instead it is defined inside ap tag when I used Inspect Element.

When select the p tag it highlights the button but the only thing inside the p tag is the text of the button within a span tag.

The p has some attributes like classes,ng-click,autom,etc

Is there anyway I can get the link of this button using selenium chrome webdrivers in python?

<div class="fr hidden-md" ng-show="flt.totalFare>0 || queryProp.rescId">
    <p class="<classs name>" analytics="<stuff>" yatratrackable="<stuff>" ng-click="makePricing({seg:flt.selectedId, from:'', ttype:queryProp.type},$event,flt);" autom="booknow">
        <span analytics="<stuff>" yatratrackable="<stuff>" class="<class name>">Book
                                Now
        </span>

        <i ng-class="currencyCode=='<code>'?'<cur>':'symbol'" ng-bind-html="currencySymbol" class="rs"><currency>
        </i>&nbsp;5,715</span>
            <i class="<class name>" ng-show="flt.clicked &amp;&amp; conf.pricingOn" style="position: absolute;margin-left:
                                        0;">
            </i>
    </p>
</div>

This is the exact code of that webpage with some minor changes.

How can I extract the link of this button with selenium?

Inspect Element shows that the button is defined in the paragraph tag

Here is the xpath that you can use to use to access Book Now button(s).

//div[@class='fr hidden-md']//p[@autom='booknow']

If you want to select the buttons by index use the index as shown below

(//div[@class='fr hidden-md']//p[@autom='booknow'])[1]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM