dpp89959 2019-05-29 07:42
浏览 111

文件从iframe获取内容

I would like to get content of a iframe with id or class of that iframe.

$links = "https://www.amazon.co.uk/Book-Secret-Wisdom-Prophetic-Evolution/dp/599054314X/ref=pd_sbs_14_2/257-3608675-7951114?_encoding=UTF8&pd_rd_i=599054314X&pd_rd_r=f103ccc1-7985-11e9-987c-178a1a538946&pd_rd_w=E5xsZ&pd_rd_wg=206kw&pf_rd_p=18edf98b-139a-41ee-bb40-d725dd59d1d3&pf_rd_r=MV7NZ41V278ECZM1135G&psc=1&refRID=MV7NZ41V278ECZM1135G";

$res = @file_get_contents($links);

$dom = new DomDocument();

@$dom->loadHTML($res);

$xpath = new DOMXpath($dom);

I would like to get content by id:

$dom->getElementById('iframeContent');

However, it alway return a page, not content of that iframe.

Anyone meet that problem?, pls help.

  • 写回答

1条回答 默认 最新

  • douyi2664 2019-05-29 08:19
    关注

    Iframes don't have content (well, they might, but it is alternative content for when iframes are not supported by the client).

    They have a src attribute containing a URL pointing at an external document.

    You need to read the src attribute value, resolve it to an absolute URL (if it isn't one already), then make an HTTP request to it, parse that, and extract the data from it.

    评论

报告相同问题?

悬赏问题

  • ¥30 python代码,帮调试
  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条