|
||
|
|
|
|||||||
| Programación y Desarrollo para Android Subforo exclusivo para temas de programación de software para PDAs y desarrollo de aplicaciones, interfaces, etc bajo Android |
![]() |
|
|
Herramientas |
|
#1
|
||||
|
||||
|
Problema con APP
Buenas, el siguiente código sirve en Java para obtener el Código Fuente de una página, el problema es que en Android he sido incapaz de conseguir obtener el "CF" y meterlo en un string para parsearlo.
Código:
public static void main(String args[]){
String s= new String();
String html = new String();
try{
URL direccio = new URL(pagina);
InputStreamReader isr = new InputStreamReader(direccio.openStream());
BufferedReader br = new BufferedReader(isr);
while((s= br.readLine())!=null)html += s + '\n';
br.close();
}catch(MalformedURLException e){
System.out.println(e);
}catch (Exception e){
System.out.println(e);
}
System.out.println(html);
}
Espero haberme explicado bien y gracias por la ayuda. |
|
|
|
#2
|
||||
|
||||
|
Yo el código fuente lo leo así
Cita: try{
try { String pURL="http://***"; URL url = new URL(pURL); // Buffer con los datos recibidos BufferedReader in = null; try { // Volcamos lo recibido al buffer in = new BufferedReader(new InputStreamReader( url.openStream())); } catch(Throwable t){} // Transformamos el contenido del buffer a texto String inputLine=""; // Mientras haya cosas en el buffer las volcamos a las // cadenas de texto while ((inputLine = in.readLine()) != null) { txt += "\n" + inputLine; } in.close(); } catch (MalformedURLException me) { System.out.println("URL erronea"); } catch (IOException ioe) { System.out.println("Error IO"); } }catch(Exception e){ //LANZA EXCEPCION CUANDO CARECE DE CONEXION A INTERNET... } ![]() |
| Gracias de parte de: | ||
|
#3
|
||||
|
||||
|
Muchas gracias x10androide, enseguida lo probare!
|