关于抓取EMS网站的问题。。

abuhome 2008-03-25 10:59:10
高分求在网页自动录入EMSNO,自动提交的功能
http://www.ems.com.cn/qcgzOutQueryAction.do?reqCode=gotoSearch

想模拟提交,取得返回的结果
这是PHP的,想写成ASP改怎么写?



CODE:[Copy to clipboard]<?php
<?php
set_time_limit(0);
error_reporting(E_ALL);

$url = "http://www.ems.com.cn/qcgzOutQueryAction.do?reqCode=gotoSearch";
$url2 = "http://www.ems.com.cn/qcgzOutQueryAction.do";
$mailNum= "EI436138259JP";
$cookie_jar= dirname(__FILE__) ."/test.cookie";


echo emsQuery($url,$url2,$mailNum,$cookie_jar);


function emsQuery($url,$url2,$mailNum,$cookie_jar){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_jar);
curl_setopt($ch,CURLOPT_COOKIE,$cookie_jar);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_NOBODY, false);
curl_setopt($ch,CURLOPT_REFERER,$url);
$content=curl_exec($ch);
preg_match('/name="myEmsbarCode" value="(.*)"/i',$content,$myEmsbarCode);
curl_close($ch);
$myEmsbarCode=$myEmsbarCode[1];


$ch2 = curl_init();
curl_setopt($ch2, CURLOPT_URL,$url2);
$post="reqCode=browseBASE&myEmsbarCode=$myEmsbarCode&mailNum=$mailNum";
curl_setopt($ch2, CURLOPT_POST, 1);
curl_setopt($ch2, CURLOPT_POSTFIELDS,$post);

curl_setopt($ch2,CURLOPT_REFERER,$url);
curl_setopt($ch2, CURLOPT_HEADER, false);
curl_setopt($ch2, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch2, CURLOPT_COOKIEFILE, $cookie_jar);
$content2 = curl_exec($ch2);
curl_close($ch2);
preg_match('/td class="txt-main" align="left">(.*)<form name="form1"/isU',$content2,$res);

return $res[1];


}
?>
这是PHP的,想写成ASP改怎么写?

这是PHP的,想写成ASP改怎么写?
...全文
163 点赞 收藏 10
写回复
10 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
abuhome 2008-03-26
谢谢 chinmo 老师.努力修改中
回复
建议你逐句捕捉分析
回复
呵呵,我给你的那个测试了没,同步吧
回复
abuhome 2008-03-26
<%
url="http://www.ems.com.cn/qcgzOutQueryAction.do?reqCode=gotoSearch"
url2 = "http://www.ems.com.cn/qcgzOutQueryAction.do"
mailNum= "EU548271726CN"

call emsQuery(url,url2,mailNum)
Sub emsQuery(url,url2,mailNum)
set objXMLHTTP = Server.CreateObject("MSXML2.XMLHTTP.5.0")
objXMLHTTP.open "GET", ""&url&"", false
objXMLHTTP.setRequestHeader "Referer",""&url&""
objXMLHTTP.send()
if InStr(objXMLHTTP.responseText, "myEmsbarCode") then
myEmsbarCode=right(replace(replace(replace(RemoveHTML(objXMLHTTP.responseText),"""",""),"=","")," ",""),13)
response.Write "<script>alert("&myEmsbarCode&");</script>"
end if

'取得了myEmsbarCode的值后开始执行查询
set objXMLHTTP2 = Server.CreateObject("MSXML2.XMLHTTP.5.0")
objXMLHTTP2.open "POST", ""&url2&"", false

objXMLHTTP2.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
objXMLHTTP2.setRequestHeader "Referer",""&url2&""

objXMLHTTP2.send("reqCode=browseBASE&myEmsbarCode="&myEmsbarCode&"mailNum="&mailNum&"")
response.Write objXMLHTTP2.responseText

set objXMLHTTP2 = nothing

End Sub
Function BytesToBstr(body)
dim objstream
set objstream = Server.CreateObject("adodb.stream")
objstream.Type = 1
objstream.Mode =3
objstream.Open
objstream.Write body
objstream.Position = 0
objstream.Type = 2
objstream.Charset = "GB2312"
BytesToBstr = objstream.ReadText
objstream.Close
set objstream = nothing
End Function

function RemoveHTML(strHtml)

Dim objRegExp, Match, Matches
Set objRegExp = New Regexp
objRegExp.IgnoreCase = True
objRegExp.Global = True
objRegExp.Pattern = "name=""myEmsbarCode"" value=""(\d*)""" ' 设置模式。

Set Matches = objRegExp.Execute(strHTML)
For Each Match in Matches
RemoveHTML=Match.Value

Next

end function
%>

还是不行..好象还少点什么?????
回复
<%
'==================================================
'函数名:GetHttpPage
'作 用:获取网页源码
'参 数:HttpUrl ------网页地址
'==================================================
Function GetHttpPage(HttpUrl)

If IsNull(HttpUrl)=True Or Len(HttpUrl)<18 Or HttpUrl="$False$" Then
GetHttpPage="$False$"
Exit Function
End If
Dim Http
Set Http=server.createobject("MSXML2.XMLHTTP")
Http.open "GET",HttpUrl,False
Http.Send()
If Http.Readystate<>4 then
Set Http=Nothing
GetHttpPage="$False$"
Exit function
else
GetHTTPPage=""
GetHTTPPage=bytesToBSTR(Http.responseBody,"GB2312")
end if

Set Http=Nothing
If Err.number<>0 then
Err.Clear
End If
End Function

'==================================================
'函数名:BytesToBstr
'作 用:将获取的源码转换为中文
'参 数:Body ------要转换的变量
'参 数:Cset ------要转换的类型
'==================================================
Function BytesToBstr(Body,Cset)
Dim Objstream
Set Objstream = Server.CreateObject("adodb.stream")
objstream.Type = 1
objstream.Mode =3
objstream.Open
objstream.Write body
objstream.Position = 0
objstream.Type = 2
objstream.Charset = Cset
BytesToBstr = Replace(objstream.ReadText,CHR(39),"'")
objstream.Close
set objstream = nothing
End Function

Response.Write GetHttpPage("http://bill.finance.sina.com.cn/bill/detail.php?stock_code=sh600210&bill_size=40000")%>

你看看这个
回复
abuhome 2008-03-26
用XMLHTTP取得了他的myEmsbarCode的值,然后再用XMLHTT传递reqCode=browseBASE&myEmsbarCode=$myEmsbarCode&mailNum=$mailNum过去,但结果输出不出来..
回复
不同步???
你怎么用的不同步?
回复
给你一个xmlHttp对象抓取网页的例子:
http://blog.csdn.net/sandyxxx/archive/2008/03/20/2199217.aspx
回复
abuhome 2008-03-25
感觉编程语言都很类似,只是我用了ASP的xmlHttp对象还是无法同步.所以故此再次发问~
回复
难道你不发觉PHP和ASP很类似???
回复
相关推荐
发帖
ASP
创建于2007-09-28

2.8w+

社区成员

ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
申请成为版主
帖子事件
创建了帖子
2008-03-25 10:59
社区公告
暂无公告