SIM
SIM

Reputation: 22440

Can't extract data using xpath

I can't extract the address out of the element I'm pasting below. It's the "br" tag which is putting a barrier for the data to get extracted.

<div class="secondary-attributes">
                    <span aria-hidden="true" data-hovercard-id="1" style="width: 18px; height: 18px;" class="icon icon--18-info icon--size-18 icon--currentColor yloca-info">
    <svg class="icon_svg">
        <use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#18x18_info"></use>
    </svg>
</span>

                                <span class="neighborhood-str-list">
            Nob Hill        </span>

                <address>
        700 Bush St<br>San Francisco, CA 94108
    </address>



    <span class="offscreen">Phone number</span>
    <span class="biz-phone">
        (415) 391-5008
    </span>

            </div>

I tried XPath like :

//div[@class="secondary-attributes"]/@address

Upvotes: 1

Views: 151

Answers (1)

Andersson
Andersson

Reputation: 52665

With //div[@class="secondary-attributes"]/@address you're trying to get attribute address from div while you need to get text content of address child element:

//div[@class="secondary-attributes"]/address/text()

If you need to extract "700 Bush St" and "San Francisco, CA 94108" separately, you might need to specify index:

//div[@class="secondary-attributes"]/address/text()[1]

for "700 Bush St" or

//div[@class="secondary-attributes"]/address/text()[2]

for "San Francisco, CA 94108"

Upvotes: 1

Related Questions