#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2004
    Posts
    317
    Rep Power
    0

    Rewriting a script - in order to make it running with php-curl


    Hello dear PHP-experts, good evening dear php-people


    i currently have some issues with the portover of a perl-project.
    And i need your help-


    i want to get get a number of websites as a screenshot - this is done best with a mozrepl-which turns the Mozilla-Firefox a port that fetches

    btw: see a link: http://curl.haxx.se/libcurl/c/curl_easy_setopt.html


    what is mozrepl:
    MozRepl a read-eval-print loop for Firefox is a Firefox extension that acts like a TCP/IP socket server within Firefox. You can then connect to the socket using any client application and send commands to Firefox. Each command you send to Firefox using MozRepl is executed as if it was run from the browser, which gives you the ability to do anything that you would normally do using Javascript.

    well the question is: how to rewrite the code in php - best would be to use Curl - i guess that Curl is
    much more powerful than

    fetch
    file_get options

    what do you think






    this is the code
    that currently runs in perl - not in php

    question; how to rewrite in php to run it in CURL


    PHP Code:
    #!/usr/bin/perl
    use strict;
    use 
    warnings;

    use 
    WWW::Mechanize::Firefox;

    my @urls qw(
        
    http://www.google.com
        
    http://www.yahoo.com
        
    http://www.cnn.com
        
    http://www.bing.com
        
    http://www.nbcnews.com
    );

    my $temp '/tmp';
    my $mech WWW::Mechanize::Firefox->new('create');

    foreach 
    my $url (@urls){
        
    my ($name) = $url =~ /www\.(\w+)\.com/;
        print 
    "creating $name.png\n";
         
        
    $mech->get($url);
        
    sleep(5);
        
    my $png $mech->content_as_png(undefundef, {width => 240height => 240});
        
        
    my $file "$temp/$name".".png";
        
    open my $fh">"$file or die "couldnt create $file";
        
    binmode $fh;
        print 
    $fh $png;
        
    close $fh;
    }

    print 
    "done\n"
    hmm - do you have a idea how to rewrite it with php and curl!?`
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 2003
    Posts
    3,497
    Rep Power
    594
    If you read your own quote on Mozrepel, the answer is, you can't. PHP and CURL cannot execute Javascript since that is a client side language that runs in a browser. The whole point of Mozrepel is so that you can run Javascript on the server side by utilizing Firefox through this interface. The downside is that you have to have Firefox active on the server.
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Dec 2004
    Posts
    2,997
    Rep Power
    375
    $mech->get($url); is where the action happens, so you could really use

    php's equivalent of file_get_content($url)

    Comments on this post

    • gw1500se disagrees : The implication (Mozrepel) that Javascript execution is needed. Your suggestion won't work in that case.

IMN logo majestic logo threadwatch logo seochat tools logo