1

这个页面http://videocamaras.com.es/index.html 正在执行JS

如何将此 JS 的输出保存到 Linux 服务器上的 Html/Php 中?

结果将是:保存的页面将显示与上面的链接相同的内容

有一个脚本吗?

谢谢

4

3 回答 3

2

正如我在评论中所说,您需要一个无头浏览器。我无法告诉您如何使用纯 PHP 来完成此操作,但我可以为您提供一些带有 Qt4 的 Python 代码。

# -*- coding: utf-8 -*-
import sys, codecs
from PyQt4.QtGui import *  
from PyQt4.QtCore import *  
from PyQt4.QtWebKit import *  

class Render(QWebPage):  
  def __init__(self, url):  
    self.app = QApplication(sys.argv)  
    QWebPage.__init__(self)  
    self.loadFinished.connect(self._loadFinished)  
    self.mainFrame().load(QUrl(url))  
    self.app.exec_()  

  def _loadFinished(self, result):  
    self.frame = self.mainFrame()  
    self.app.quit()  

url = 'http://videocamaras.com.es/index.html'

r = Render(url)  
html = unicode(r.frame.toHtml())

sys.stdout = codecs.getwriter('utf-8')(sys.stdout)
print html

那会得到你想要的。

于 2012-10-16T10:25:22.227 回答
1

获取 index.html 文件的内容:

$url = 'http://videocamaras.com.es/index.html';
$file = '/some/path/on/your/server/index.html';
$contents = file_get_contents($url);
if (!is_dir(dirname($file)) {
    mkdir(dirname($file), 2775, true);
}
file_put_contents($contents);

在这里,您只是获取位于 的文档的内容$url,确保目标路径存在,然后将内容放入$file.

为此,您应该在 .htaccess 文件中包含 php_flag allow_url_fopen 1 。

希望能帮助到你。

于 2012-10-16T09:21:07.340 回答
0

您可以使用file_get_contents

$output = file_get_contents("http://videocamaras.com.es/index.html")

http://videocamaras.com.es/index.html的完整输出存储在 $output 中,您可以将其保存在数据库中。

于 2012-10-16T09:20:36.980 回答