Getting source of webpage

Problems with WiFi, SQLite ,Bluetooth, WiMax, Proxies, etc...

Getting source of webpage

Postby nr1 » Tue Aug 11, 2009 6:29 pm

Hi,

what is the easiest way to get the source of a webpage in a string variable?

thx
nr1
Junior Developer
Junior Developer
 
Posts: 24
Joined: Tue Aug 11, 2009 6:27 pm

Top

Postby Romeo Ordos » Wed Aug 12, 2009 10:43 am

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. String tmpstr;
  3.  
  4. HttpClient client = new DefaultHttpClient();
  5.  
  6. HttpGet get = new HttpGet("http://some.url.com");
  7.  
  8. try
  9.  
  10.  HttpResponse rsp = client.execute(get);
  11.  
  12.  tmpstr = EntityUtils.toString(rsp.getEntity());
  13.  
  14. catch (ClientProtocolException e)
  15.  
  16.  {
  17.  
  18.   // TODO
  19.  
  20.  }
  21.  
  22. catch (IOException e)
  23.  
  24.  {
  25.  
  26.   // TODO
  27.  
  28. }
  29.  
  30.  
Parsed in 0.032 seconds, using GeSHi 1.0.8.4


tmpstr is your string with sourcecode.
Romeo Ordos
Junior Developer
Junior Developer
 
Posts: 11
Joined: Thu Aug 06, 2009 6:30 pm
Location: Donetsk, Ukraine

Postby nr1 » Wed Aug 12, 2009 6:11 pm

thx!
nr1
Junior Developer
Junior Developer
 
Posts: 24
Joined: Tue Aug 11, 2009 6:27 pm

Postby porzino » Thu Oct 08, 2009 3:21 pm

Hi,

I have try this solution and I have a problem: I only get the first 8K of the web (The size is 300K)

Any ideas?
porzino
Freshman
Freshman
 
Posts: 2
Joined: Thu Oct 08, 2009 3:17 pm

Top

Return to Networking & Database Problems

Who is online

Users browsing this forum: No registered users and 2 guests