本页http://videocamaras.com.es/index.html 正在执行JS
如何将此 JS 的输出保存到 Linux 服务器上的 Html/Php 中?
结果将是:保存的页面将显示与上面的链接相同的内容
有脚本吗?
谢谢
最佳答案
正如我在评论中所说,为此您需要一个 headless 浏览器。我无法告诉您如何使用纯 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
这将得到你想要的。
关于php - 使用 Javascript 输出保存 Html,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12911308/