Your browser doesn't support iframes?

edited October 2013 in Questions about Code

hello,

I have run into this problem recently where I request a page from http://start.csail.mit.edu/ and it returns with

Your browser doesn't support iframes

before I could request start.csail.mit.edu/answer.php?query=what+are+apples and it would work fine.

The code is:

String lines[] = loadStrings("http://start.csail.mit.edu/answer.php?query=what+are+apples");
println("there are " + lines.length + " lines");
for (int i = 0 ; i < lines.length; i++) {
  println(lines[i]);
}

any suggestions on how to resolve this? Thanks in advance.

Answers

  • You probably need to use the Network Client to send a User-Agent string in the request. Some bad sites try to guess the browser and to serve pages differently depending on the result.

  • I have tried it with what you have suggested and still not getting the right results.

    import processing.net.*;
    
    
    
    Client c;
    
    String data;
    
    String domain = "start.csail.mit.edu";
    
    String addr = "/answer.php?query=what+are+apples";
    
    
    
    void setup() { 
    
      size(200, 200); 
    
      background(50); 
    
      fill(200); 
    
      c = new Client(this, domain, 80); // Connect to server on port 80 
    
    
    
        c.write("GET "+addr+" HTTP/1.1\r\n"); // Can replace / with, eg., /reference/ or similar path
    
      c.write("User-Agent: Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.17 Safari/537.36\r\n");
    
      c.write("Host: "+domain+"\r\n"); // Which server is asked
    
    
     // c.write("Accept: application/xml,application/.html+xml,text.html;q=0.9,text/plain;q=0.8,image/png,*//*;q=0.5\r\n");
    
      c.write("Accept-Language: en-us,en;q=0.5\r\n");
    
      c.write("Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7\r\n");
    
      c.write("\r\n");
    } 
    
    
    
    void draw() {
    
      if (c.available() > 0) { // If there's incoming data from the client...
    
        data = c.readString(); // ...then grab it and print it
    
        println(data);
      }
    }
    
  • Well, your code get the page I see when I visit the URL you gave, so I am not sure what is wrong for you...

    I suppose the annoying part is there is a redirection, or an Ajax call (JavaScript) that fetches the real results and display them later.

    Something much harder to automate in Processing... Unless you find out what is the Rest API on the server side.

  • I looked what are the requests made in the page after the loading, and found out that the URL of the real query is now:

    http://start.csail.mit.edu/justanswer.php?query=what+are+apples

Sign In or Register to comment.