网抓(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>

这个先放着,回头补充。

posted @ 2018-03-15 15:55  怎么著都不成  阅读(3652)  评论(0编辑  收藏  举报