ofir
ofir

Reputation: 33

Saving Html with Java Script output

This page http://videocamaras.com.es/index.html Is executing JS

How can I save the output of this JS into Html/Php on Linux server ?

Result will be : Saved page that will show the same content as the link above

There is a script for that ?

Thank you

Upvotes: 1

Views: 874

Answers (3)

alexandernst
alexandernst

Reputation: 15099

As I said in a comment, you need a headless browser for this. I can't tell you how this could be done using pure PHP, but I can give you some code for Python with Qt4.

# -*- 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

That will get what you want.

Upvotes: 2

Saul Martínez
Saul Martínez

Reputation: 920

Get the contents of the index.html file:

$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);

Here you are just getting the contents of the document located at $url, ensuring the destination path exists and then putting the contents in $file.

For this to work, you should have php_flag allow_url_fopen 1 in you .htaccess file.

Hope it helps.

Upvotes: 1

Oritm
Oritm

Reputation: 2120

You can use file_get_contents

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

The complete output of the http://videocamaras.com.es/index.html is stored in $output, and you can save that in a database.

Upvotes: 0

Related Questions