2015-01-22 2 views
0

CSS가 포함 된 노드가 있습니다. XPath를 사용하여 background-image: url()을 얻으려고합니다. 인라인 CSS 배경 이미지 가져 오기

<div class="ytp-thumbnail html5-stop-propagation" style="background-image: url(https://i.ytimg.com/vi_webp/lm5CLm4ciQg/hqdefault.webp);">

내 지금까지 시도하고 불완전한 경로가 클래스 ytp-thumbnail하지만 ytp-thumbnail html5-stop-propagation 일치하지 않기 때문에 //div[@class="ytp-thumbnail"]/@style/

답변

0

당신의 XPath를 작동하지 않는 것입니다. 경우

//div[contains(@class,"ytp-thumbnail")]/@style 

반환

style="background-image: url(https://i.ytimg.com/vi_webp/lm5CLm4ciQg/hqdefault.webp);" 

만 값을 원하는 당신을 : 그것은 모두

//div[@class = "ytp-thumbnail html5-stop-propagation"]/@style 

를 사용하거나 클래스 속성 contains()ytp-thumbnail이 경우 단지 확인 일치 있는지 확인할 수 있습니다 이용 가능 string() :

string(//div[contains(@class,"ytp-thumbnail")]/@style) 
,

반환

background-image: url(https://i.ytimg.com/vi_webp/lm5CLm4ciQg/hqdefault.webp); 

그리고 경우에 당신은 URL의 값이, 당신이 substring-before()substring-after()을 사용할 수 원하는 : 추가

https://i.ytimg.com/vi_webp/lm5CLm4ciQg/hqdefault.webp 

참고 것을

substring-before(substring-after(string(//div[contains(@class,"ytp-thumbnail")]/@style),'url('),')') 

반환하여 끝 부분의 / 때문에 XPath가 작동하지 않음 - 대신- /@style을 사용할 때 XPath에서 이미 스타일 속성을 선택 했으므로