【问题标题】:php simple html dom and iframe srcphp 简单的 html dom 和 iframe src
【发布时间】:2018-07-10 06:53:31
【问题描述】:
require('simple_html_dom.php');
    // Create DOM from URL or file
    $html = file_get_html('https://www7.fmovies.se/film/hometown-hero.m2r28/6xpjrp');
    foreach($html->find('div[id=player]') as $div)
    {
     foreach($div->find('iframe') as $iframe)
       {
             echo $iframe->src;

       }
    }

这是我的代码,正如您所见,我正在尝试使用 PHP Simple HTML DOM Parser 在播放器 div 下获取 iframe 的 src,您能否向我解释一下为什么我会得到一个空白页面? 谢谢!

更新:使用 javascript 切换器插件并禁用 javascript 后,我​​注意到我正在寻找的 iframe 未加载。我应该怎么做才能获得 iframe src?

【问题讨论】:

  • 转到该页面,查看源代码并搜索“
  • @pguardiario iframe 在点击后加载 iframe,执行加载 iframe 的 javascript 代码

标签: php dom iframe web-scraping simple-html-dom


【解决方案1】:

有两种可能的解决方案;

  1. 尝试弄清楚 javascript 是如何工作的,并在您的 PHP 脚本中模拟这种行为。

  2. 让页面加载到例如 selenium 中,然后使用 selenium 从 iframe 中获取 SRC。 (https://www.seleniumhq.org/)

希望对你有帮助

【讨论】:

  • 感谢您的回复,通过javascript点击链接后会加载iframe
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-02-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多