B
B
bravecollector2020-09-14 12:31:41
HTML
bravecollector, 2020-09-14 12:31:41

How to extract URL using XPath?

Hello.
I need to pull http://site.ru/from the following code:

<div class="one">
<dl>
<dt class="two">
<span class="name">Site</span>
</dt>
<dd class="three">
<span class="js-pseudo-link" data-url="rAnDoMlEtTeRsAnDnUmBeRs" style>
<a href="http://site.ru/" class rel="nofollow" target="_blank" style> http://site.ru/ </a>
</span>
</dd>
</dl>
</div>


I do this: //div//dl//dd//span//a/@href
Nothing comes out.

I started to get acquainted with XPath recently, incl. Maybe the question is obvious, but I did not find a sensible answer.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Alexey Sundukov, 2020-09-14
@bravecollector

I do this: //div//dl//dd//span//a/@href

For the given piece of code, this is a working expression. You have a different problem. Most likely, the reason is that the site does not have this code in the source code of the page and the text is pulled through JS via AJAX. In this case, you should use selemiun web driver.

R
Rsa97, 2020-09-14
@Rsa97

Enough //a/@href
xpather.com/8rf5k32K

K
krypt3r, 2020-09-14
@krypt3r

//div/dl/dd/span/a/@href

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question