Ver Mensaje Individual
  #1 (permalink)  
Antiguo 04/05/2012, 15:51
Fhernd
 
Fecha de Ingreso: junio-2008
Ubicación: Bogotá Colombia
Mensajes: 45
Antigüedad: 16 años, 8 meses
Puntos: 0
Pregunta Recuperar código fuente de otro sitio Web

Hola comunidad FDW,

Estoy desarrollando una extensión sencilla para Chrome, pero llevo ya algunos minutos averiguando cómo recuperar el código HTML de una dirección (e.g.: www.google.com) y luego recuperar un elemento por su ID. O iterar por una colección de elementos de determinada etiqueta (div, por ejemplo).

He probado algunos código, como:

Código:
<HTML>
<head>

<script language=javascript> 

function getcontent(acc, ind, key) {

var url = "http://www.mendhak.com/main.php";
var xmlhttp = new ActiveXObject("MSXML2.ServerXMLHTTP"); 
xmlhttp.open("GET", url, 0); 
xmlhttp.send(""); 
var xmlhttp = null; 
document.write(xmlhttp.responseText);
}

</script>

</head>
<body>
Hello

<b><a href="javascript:getcontent(0,0,'tyhfx')">get content</a></b>

</body>
</HTML>
Código:
Ç<html>
<head>
<script type="text/javascript">
function loadXMLDoc()
{
var xmlhttp;
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","ajax_info.txt",true);
xmlhttp.send();
}
</script>
</head>
<body>

<div id="myDiv"><h2>Let AJAX change this text</h2></div>
<button type="button" onclick="loadXMLDoc()">Change Content</button>

</body>
</html>
Pero no he obtenido ningún resultado satisfactorio.

¿Me podrían dar sugerencias para tratar de resolver este caso?

Gracias de antemano.
Hasta pronto.