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