문제

In any YouTube video page (Gangnam Style for example), some elements can't be accessed by their XPath. From example, I'm trying to access the "Show more" button

enter image description here

by getting its XPath from the Inspect Window

enter image description here

and using this code

btn=$x('//*[@id="widget_bounds"]/div[2]/div[4]/div[7]/div[3]/span[1]');

but I get nothing, or more precisely, an empty list:

enter image description here

I've never encountered this problem before, are they using some sort of obfuscation trickery to prevent the item from being accessed?

Is there a way to work around it?

도움이 되었습니까?

해결책

The content you want to reach is in an iframe on the page. BUT the problem is you will not be able to get to the content because the Same Origin Policy is going to prevent it.

document.getElementById("I0_1392927253257").contentWindow.document

SecurityError: Blocked a frame with origin "http://www.youtube.com" from accessing a cross-origin frame.

Check out @sashoalm's link below to change the context of iframe in Chrome.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top