1

I'm trying to retrieve an url form background-image. So far i've managed to get the style however i can't seem to only get url.

What i managed so far:

//div[@class='opponent opponent1']/div[@class='team-player']/@style

Html example:

<div class="opponent opponent1">
    <div class="team-player" style="background-image: url('/uploads/test.jpeg')"></div>
    <h3><a href="#">Team EnVyUs</a></h3>
</div>

2 Answers 2

1

The combination of substring-before and substring-after should do the trick:

substring-before(substring-after(//div[@class='opponent opponent1']/div[@class='team-player']/@style, "background-image: url('"), "')")
Sign up to request clarification or add additional context in comments.

1 Comment

Hi, can u help find why your solution dont work fo me? stackoverflow.com/questions/47048955/… , tks
1

I think you are done with XPATH once you have selected the intended element. If you already got the style value you can use RegEX to get the url.

attribute.value.match(new RegEx("'(.*?)'"))[0];

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.