我想将这个远程页面的HTML源代码加载到PHP中的字符串中,使用这个极棒的Galantis音乐视频https://www.youtube.com/watch?v=5XR7naZ_zZA作为示例。将HTML源代码加载到PHP中的字符串
然后我想在源代码中搜索特定的div id“action-panel-details”并确认它何时被发现。使用下面的代码,整个页面会简单地加载到我在服务器上运行的页面上。
这甚至有可能与file_get_contents()?这是所加载的网页,视频和所有代码:
<?php
$str = file_get_contents('https://www.youtube.com/watch?v=5XR7naZ_zZA');
if(preg_match("~action-panel-details~", $str)){
echo "it's there";
}
?>
我一直在使用使用simplexml_load_file()也与此错误结束了尝试:
Warning: simplexml_load_string(): Entity: line 1: parser error : xmlParseEntityRef: no name in /page.php on line 5
Warning: simplexml_load_string(): ndow, document);</script><script>var ytcfg = {d: function() {return (window.yt & in /page.php on line 5
Warning: simplexml_load_string():^in /page.php on line 5
Warning: simplexml_load_string(): Entity: line 1: parser error : xmlParseEntityRef: no name in /page.php on line 5
这就是会产生的代码:
<?php
$str = file_get_contents('https://www.youtube.com/watch?v=5XR7naZ_zZA');
$str = simplexml_load_string($str);
if(preg_match("~watch-time-text~", $str)){
echo "it's there";
}
?>
任何帮助,非常感谢。
非常感谢。第一个解决方案是为我工作。 – bethbee