douyangqian5243 2018-08-17 21:57
浏览 116
已采纳

使用PHP获取加载的操作HTML dom

I tried to get a loaded and with Javascript manipulated HTML dom, with PHP. But it only returns the documents content.

For me it seems to be, that theres no solution :(

Example:

index.php
$dom = new DOMDocument();
$dom->load('test.html');
$html = $dom->getElementsByTagName("html")->item(0);
echo $html->nodeValue;

Result:

title
var test = document.createElement("div");
test.innerHTML = "test";
document.body.appendChild(test);

I try all to get this result:

<head>
<title>title</title>
</head>
<body>
<div>test</div>
</body>
  • 写回答

1条回答 默认 最新

  • dqd3690 2018-08-17 22:04
    关注

    You can't. At least, not with PHP alone. The PHP DOM extension does not include a Javascript interpreter; it will only report on the literal contents of the HTML file.

    It might be possible to load the document into a headless browser, like PhantomJS. But this will be a lot more work, and isn't possible without using a significant amount of software outside the PHP standard library.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 curl 命令调用正常,程序调用报 java.net.ConnectException: connection refused
  • ¥20 关于web前端如何播放二次加密m3u8视频的问题
  • ¥15 使用百度地图api 位置函数报错?
  • ¥15 metamask如何添加TRON自定义网络
  • ¥66 关于川崎机器人调速问题
  • ¥15 winFrom界面无法打开
  • ¥30 crossover21 ARM64版本安装软件问题
  • ¥15 mymetaobjecthandler没有进入
  • ¥15 mmo能不能做客户端怪物
  • ¥15 osm下载到arcgis出错