网抓(XML Http Request、VBA)实现


第一种,先看VBA

Public Function GetInfo(strMoblie As String) As String
    '创建对象
    Dim xmlHttp As Object
    Set xmlHttp = CreateObject("MSXML2.XMLHTTP")
    '发送请求
    xmlHttp.Open "GET", "http://www.ip138.com:8080/search.asp?action=mobile&mobile=" & strMoblie, False
    xmlHttp.Send    '等待响应
    Do While xmlHttp.ReadyState <> 4
        DoEvents
    Loop
   '得到请求数据
   Dim strReturn As String
   strReturn = xmlHttp.ResponseText
   GetInfo = strReturn
End Function

第二种,XML Http Request,是不是似曾相识呀

<html>
<head>
<script type="text/javascript">

xmlHttp=null;

function showHint(str)
{
if (str.length==0)
  { 
  document.getElementById("txtHint").innerHTML="";
  return;
  }
try
  {// Firefox, Opera 8.0+, Safari, IE7
  xmlHttp=new XMLHttpRequest();
  }
catch(e)
  {// Old IE
  try
    {
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  catch(e)
    {
    alert ("Your browser does not support XMLHTTP!");
    return;  
    }
  }
url="/ajax/gethint.asp?q=" + str;
url=url+"&sid="+Math.random();
xmlHttp.open("GET",url,false);
xmlHttp.send(null);
document.getElementById("txtHint").innerHTML=xmlHttp.responseText;
}
</script> 
</head>
<body><form> 
First Name:
<input type="text" id="txt1"
onkeyup="showHint(this.value)">
</form><p>Suggestions: <span id="txtHint"></span></p> </body>
</html>

这个先放着,回头补充。


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM