|
本帖最后由 liangstar82 于 2015-9-28 09:34 编辑
吴姐,能帮忙看一下如下代码吗?关于ASPX网页动态参数获取数据的例子。
Private Sub CommandButton1_Click()
'网站:http://www.hkexnews.hk/listedco/ ... _active_main_c.aspx
'在香港交易所网站,获取港股: 00001 (长和 )的历史文件通告,目标内容如QQ截图:记录内容.PNG 所示
Dim strText As String, t, n, myfla As Boolean, m, mdate, p, mynum, arrcol, ar, arr, arrdata, arrall
Dim Pd1 As Boolean, Pd2 As Boolean, url As String, url1 As String
Dim VIEWSTATE As String, stockcode As String
Dim DocType As String, KeyWord As String
With ActiveSheet
t = Timer: n = 1: myfla = True
mdate = CStr(Format(Date, "yyyymmdd"))
stockcode = CStr(.[D2].Value)
With CreateObject("MSXML2.XMLHTTP")
url = "http://www.hkexnews.hk/listedco/listconews/advancedsearch/search_active_main_c.aspx"
.Open "GET", url, False
.Send
strText = .responsetext
VIEWSTATE = encodeURI(CStr(Split(Split(strText, "__VIEWSTATE"" value=""")(1), """ />")(0)))
url1 = "http://www.hkexnews.hk/listedco/listconews/advancedsearch/search_active_main_c.aspx"
.Open "POST", url1, False
.Send "__VIEWSTATE=" & VIEWSTATE _
& "&ctl00$txt_today=" & mdate _
& "&ctl00$hfStatus=ACM" _
& "&ctl00$txt_stock_code=" & stockcode _
& "&ctl00$rdo_SelectDocType=rbAll" _
& "&ctl00$sel_tier_1=-2" _
& "&ctl00$sel_DocTypePrior2006=-1" _
& "&ctl00$sel_tier_2_group=-2" _
& "&ctl00$sel_tier_2=-2" _
& "&ctl00$ddlTierTwo=59,1,7" _
& "&ctl00$ddlTierTwoGroup=2,1" _
& "&ctl00$rdo_SelectDateOfRelease=rbManualRange" _
& "&ctl00$sel_DateOfReleaseFrom_d=01" _
& "&ctl00$sel_DateOfReleaseFrom_m=04" _
& "&ctl00$sel_DateOfReleaseFrom_y=1999" _
& "&ctl00$sel_DateOfReleaseTo_d=" & Mid(mdate, 7, 2) _
& "&ctl00$sel_DateOfReleaseTo_m=" & Mid(mdate, 5, 2) _
& "&ctl00$sel_DateOfReleaseTo_y=" & Mid(mdate, 1, 4) _
& "&ctl00$rdo_SelectSortBy=rbDateTime"
strText = .responsetext
LoadTotxt (strText)
End With
End With
End Sub
Function LoadTotxt(strText)
Open ThisWorkbook.Path & "\allshowing.txt" For Output As #1
Print #1, strText
Close #1
End Function
Public Function encodeURI(strText) As String
With CreateObject("msscriptcontrol.scriptcontrol")
.Language = "JavaScript"
encodeURI = .Eval("encodeURIComponent('" & strText & "');")
End With
End Function
发现 Requext框 WebForms 里面的__VIEWSTATE动态参数,总是和 Requext框 Raw里面的__VIEWSTATE动态参数不一致。
不知是何缘故。
我传附件上来,恳请吴姐指点迷津。
mytest.zip
(60.06 KB, 下载次数: 35)
|
|