我如何使用MSXML2.ServerXMLHTTP从其他网站抓取数据? [英] How do I use MSXML2.ServerXMLHTTP to grab data from another site?

查看:564
本文介绍了我如何使用MSXML2.ServerXMLHTTP从其他网站抓取数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有如下因素链接: http://mvp.sos.state.ga.us/

We have the folowing link: http://mvp.sos.state.ga.us/

而不是创建一个数据库复制信息MVP页面,我们想用我们自己的表单,然后在幕后,将信息发送到网站上面找回使用名为MSXML2.ServerXMLHTTP组件的结果。

Rather than create a db to replicate information that MVP page, we would like to use our own form, and then behind the scenes, send information to the site above to get results back using component called MSXML2.ServerXMLHTTP.

不幸的是,我对此一无所知组件或如何使用它。

Unfortunately, I know nothing about this component or how to use it.

会有人好心地取悦给我如何使用我们自己的......将信息发送到网站上面,并得到结果返回给我们的表格指针?

Would someone be kind enough to please give me pointers on how use our own ... to send information to the site above and get results back to our form?

我们基本上是试图让用户输入首字母,姓氏,县,出生日期。

We are basically trying to get users to enter first initial, lastname, county, date of birth.

感谢

推荐答案

您可以使用像POSTHTTP的请求这个组件,GET,删除等。

You can use this component for http-requests like "POST", "GET", "DELETE" etc.

创建对象:

<%
    Set objXML = Server.CreateObject("MSXML2.ServerXMLHTTP")
%>

要发送的使用方法GET数据:

<%
    objXML.Open "GET", "http://mvp.sos.state.ga.us/?some=querystring", false 
    objXML.Send("")
    Response.Write objXML.responseText
%>

注意,打开方法有3个参数。的方法,URL,acynchronous通话

请注意,发送方法没有参数。 (此处我们使用GET作为方法,因此,我们就不需要从这里发送任何数据,相反,我们使用查询字符串的数据传递到URL)

Note that Send method has no parameters. (here we are using "GET" as the method, so, we don't need to send any data from here, instead we pass the data into the url using the querystring)

要使用的方法POST发送数据:

<%
    objXML.Open "POST", "http://mvp.sos.state.ga.us/", false 
    objXML.Send("username=htbasaran&password=somepassword")
    Response.Write objXML.responseText
%>

请注意,发送方法有1个参数。的数据的。 (在这里我们使用的是POST的方法,因此,我们需要在这里发送数据的键 - 值对格式,如:键1 =值&放大器;键2 =值&放大器;等等=上... 的或任何其他数据一样的 XML 的等)

Note that Send method has 1 parameter. data. (here we are using "POST" as the method, so, we need to send data here in key-value pairs format like: key1=value1&key2=value2&so=on... or any other data like xml etc.)

这是这个组件的基础知识。如果您需要了解更多信息,您可以检查<一href=\"http://msdn.microsoft.com/en-us/library/windows/desktop/ms766431%28v=vs.85%29.aspx\">microsoft's文档页面了。

These are the basics of this component. If you need more information, you can check microsoft's docs page out.

一个例子code获取表单值和使用XMLHTTP POST方法发送传真。

<%
    ' getting form values
    my_uname = Request.Form("username")
    my_pword = Request.Form("password")

    ' creating object
    Set objXML = Server.CreateObject("MSXML2.ServerXMLHTTP")

    ' sending variables to an external site
    objXML.Open "POST", "http://www.sitename.com/login.asp", false
    objXML.Send("username=" & my_uname & "&password=" & my_pword)

    ' considering if the login was successfull, response would be "Ok", else "kO"
    ' writing the result to the client.
    if objXML.responseText="Ok" then
        Response.Write "Login Successful!"
    else
        Response.Write "Login Failed!"
    end if
%>

这篇关于我如何使用MSXML2.ServerXMLHTTP从其他网站抓取数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆