1

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

1
  • You need a headless browser that will run the JS inside the page. Commented Oct 16, 2012 at 9:18

3 Answers 3

2

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.

Sign up to request clarification or add additional context in comments.

4 Comments

Thanks Alexander - My server do not support Python - Any other alternatives ?
You can use that same code (with some small changes) to adapt it to C++ and Qt4. Then you can compile it statically and you'll be free of dependencies. Another way is searching for some other headless browser. There are some really good ones, like phantomjs.org or zombie.labnotes.org . Just search for "headless browser" in google and choose the one you most like.
videocamaras.com.es/u.js - Is it possible to convert this code to PHP that will write directly on server ?
Yes, it is, but it will be easier for you to do it the headless-browser-way .
1

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.

7 Comments

This is the correct code for the given answer - bus as said do not save JS output<?php $url = 'videocamaras.com.es/index.html'; $file = '/home/zzzzz/public_html/videos2.html'; $contents = file_get_contents($url); if (!is_dir(dirname($file))) { mkdir(dirname($file), 2775, true); } file_put_contents($file, $contents); ?>
I'm not pretty sure, but as far as I know javascript runs in the browser only.
If you want to get the contents of that page periodically or even for more pages, running a script like the one @alexandernst just suggested would be your answer.
@SaulMartínez You're not understanding what he wants. The site he point to runs some JS that inserts HTML in the DOM after the page is loaded. You need to load that page, load the JS inside it, let the JS run, let the JS do it's job with the DOM and then output the result.
Yeah, I didn't understand quite right the first time I read the question, but then got it right, that's why I'm pointing that you script, or something similar would be a better approach. I'm actually going to figure out how to get this using php, using curl perhaps. (:
|
0

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.

1 Comment

Thank you for the answers - The codes given copy original Html But do not save html after JS was executed - I want to save the text near the video

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.