Search Different Strings and Save Each String Search Result Separately in a Loop...?

5 views
Skip to first unread message

Mehdi Esteghamatian

unread,
Jun 11, 2016, 5:05:12 AM6/11/16
to phantomjs
Hi All,

I like to search a list of search strings using PhantomJS and Save the results but for some reason it is not working and it only saves the last string search result page.

Below is the code.

Any input is well appreciate it.

Thank you 



    var AddressList  = [
       'ODEON & UCI Cinemas Milton Keynes, United Kingdom'
      ,'GP Bullhound  London, United Kingdom'
      // ,'G4S London, United Kingdom'
      // ,'Lloyds Banking Group  London, United Kingdom'
      ];

    var i = 0;

    function pausecomp(millis)
    {
        var date = new Date();
        var curDate = null;
        do { curDate = new Date(); }
        while(curDate-date < millis);
    }

    for (i = 0; i < AddressList.length; i++)
    {
        var page = require('webpage').create();// new WebPage()
        var fs = require('fs');
        // page.onLoadFinished = function() {
        //   console.log("page " + i + " load finished");
        //   page.render('export.png');
        //   fs.write('File_'+(new Date()).getTime()+'.html', page.content, 'w');
        //   phantom.exit();
        // };

        page.index = i + "_";
        page.onLoadFinished = function() {
            console.log("page " + this.index + " load finished");
            page.render('export.png');
            fs.write('File_'+(new Date()).getTime()+'.html', page.content, 'w');
        };

        page.open("https://www.google.com/?gws_rd=ssl#q="+encodeURIComponent(AddressList[i]), 
          function()
              {
                  page.evaluate(function() { });
              });

        // pausecomp(10000);
    }
    // phantom.exit();




Reply all
Reply to author
Forward
0 new messages