Python - getHTMLpage


/ Published in: Python
Save to your folder(s)



Copy this code and paste it in your HTML
  1. package HttpGetIMGs;
  2.  
  3. import java.io.BufferedReader;
  4. import java.io.IOException;
  5. import java.io.InputStreamReader;
  6. import java.io.OutputStreamWriter;
  7. import java.net.MalformedURLException;
  8. import java.net.URL;
  9. import java.net.URLConnection;
  10. import java.net.URLEncoder;
  11.  
  12. /*
  13. *
  14. * Fa una richiesta di connessione al web e scarica la pagina...
  15. */
  16.  
  17. public class RandomIMGs
  18. {
  19. private BufferedReader br;
  20. private OutputStreamWriter osw;
  21. private String data;
  22. private String line;
  23. private URL url;
  24. private URLConnection conn;
  25.  
  26. public RandomIMGs()
  27. {
  28. try
  29. {
  30. url = new URL("http://flickr.com/photos");
  31. conn = url.openConnection();
  32. conn.setDoOutput(true);
  33.  
  34. osw = new OutputStreamWriter(conn.getOutputStream());
  35.  
  36. data = URLEncoder.encode("start", "utf-8") + "=" + URLEncoder.encode("1", "utf-8");
  37. osw.write(data);
  38. osw.flush();
  39.  
  40. br = new BufferedReader(new InputStreamReader(conn.getInputStream()));
  41.  
  42. while((line = br.readLine()) != null)
  43. {
  44. System.out.println(line);
  45. }
  46.  
  47. osw.close();
  48. br.close();
  49. }
  50. catch(MalformedURLException e)
  51. {
  52. e.printStackTrace();
  53. }
  54. catch(IOException e)
  55. {
  56. e.printStackTrace();
  57. }
  58. }
  59.  
  60. public static void main(String[] args)
  61. {
  62. new RandomIMGs();
  63. }
  64. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.