0

How can I get a specific GET Request and the information in this request like https://example.de/ca.aspx?campaign=123456&pitype=Content via PhantomJS or another headless browser?

Vega
  • 2,661
  • 5
  • 24
  • 49
  • Okay, I will ask the other questions seperatly, edited this thread for the GET Request problem. – Vega Aug 23 '15 at 19:17
  • 1
    What exactly do you mean by "get a specific GET Request"? Do you mean the the response content? If so, then no that's not easily possible with PhantomJS ([CasperJS example](http://stackoverflow.com/questions/24555370/how-can-i-catch-and-process-the-data-from-the-xhr-responses-using-casperjs)). – Artjom B. Aug 23 '15 at 19:21
  • Something like this: https://github.com/ariya/phantomjs/issues/11483 This script gives me all GET requests from a homepage, but I need just the one for a specific site like https://example.de/ca.aspx (and the query string that is in this GET request) Firebug screenshot: http://postimg.org/image/ozw6y3mjb/full/ – Vega Aug 23 '15 at 19:24
  • You can match (a part of) the URL in a way like it's shown in the documentation: http://phantomjs.org/api/webpage/handler/on-resource-requested.html (Example 2) – Artjom B. Aug 23 '15 at 19:29

1 Answers1

0
var Url = "http://www.google.de";
var params = new Array();
var webPage = require('webpage');
var page = webPage.create();
var targetJSON = {};
page.open(Url);
// the request url you want to catch
page.onResourceRequested = function(requestData, networkRequest) {
var match = requestData.url.match(/google.com\/test.aspx/g);
if (match != null) {
    var targetString = decodeURI(JSON.stringify(requestData.url));
    var klammerauf = targetString.indexOf("{");
    var jsonobjekt = targetString.substr(klammerauf, (targetString.indexOf("}") - klammerauf) + 1);
// request contains some JSON stuff in my case, so I decode it as a JSON object
    targetJSON = (decodeURIComponent(jsonobjekt));
    console.log(targetJSON);
    phantom.exit();
} 

};
Vega
  • 2,661
  • 5
  • 24
  • 49