php - PHP:加载 JS 事件后获取远程页面
问题描述
我正在使用一种简单的方法来加载大部分工作正常的远程网页:
$output = file_get_contents($item['URL']);
$html->loadHTML($output);
之后我可以按类型或名称或ID搜索标签,但问题是我想要的主要内容是在最后一秒由JS生成的。在浏览器中加载时,您不会注意到它,但是当尝试使用 file_get_contents 获取它时,我得到的页面是在最后一分钟 JS 运行之前存在的。
这是加载我想要的内容的部分代码,因此您可以了解我的意思,但它非常简单:我得到的页面不是“完整”页面。
<script type="text/javascript">ImageMachine.prototype.ImageMachine_Generate_Thumbnail = function (thumbnail_image, main_image, closeup_image, type_code) {
var thumbnail,
img;
我也尝试过使用 CURL,但没有运气。
$header[] = "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,;q=0.8";
$header[] = "Connection: keep-alive";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $item['URL']);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header_str);
// curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_COOKIE, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_ENCODING, '');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_USERAGENT, $this_time);
$output = curl_exec($ch);
curl_close($ch);
@$html->loadHTML($output);
有没有办法得到整个东西?我希望浏览器或用户在加载页面时会看到相同的页面。
解决方案
推荐阅读
- node.js - 如何在没有守卫装饰器的情况下始终验证 JWT?(Nest.js + 护照)
- java - h2 在处理 qnap 服务器上的许多文件的 h2 上用完文件描述符
- batch-file - 打开适合模型的正确版本的 EB GUIDE
- r - 按类别分组,然后找出类别之间的差异 [r]
- julia - 如何显示二阶数值微分的截断误差是一阶数值微分的平方
- kubernetes - 在 Kubernetes 中使用分片的生产 Redis 集群
- java - 禁止所有带有 PMD 和 XPath 的 java.sql 包
- pandas - 如何解决 pandas 中 set_index 函数的问题
- sql - 使用每一行作为 Insert Into 循环遍历表的行 - SQL
- postgresql - 用于从 PostgreSQL 表中过滤/聚合结果的 GraphQL 查询结构