Search code examples
web-scrapingxpath

Find xpath element text on scrape


Need some help on getting the content (text) of the anchor that hold the email address while performing a scrape. I've tried //*[@id="panel"]/p[2]/span[2]/a but my problem is that not always the span appears as the 2nd child. I presume if I could target the element with the href mailto would work but unable to do it.

<div id="panel">
<p>Elements here</p>
<p>
    <span class="label">Email:</span>
    <span class="content">
        <a class="link" href="mailto:[email protected]">
            [email protected]
        </a>
    </span>
</p>
<p></p>
</div>

Solution

  • Use contains()

    //div[@id="panel"]//a[contains(@href,"mailto:")]