分享

网抓(XML Http Request、VBA)实现

 刮骨剑 2018-12-26

第一种,先看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>

这个先放着,回头补充。

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多