|
我看了论坛里面很多的网页抓取,实在是很难理解,在此求助大家。
http://club.excelhome.net/thread-1156325-1-1.html
问题1:
Sub test()
Columns("A:E").ClearContents
Set html = CreateObject("htmlfile")
With CreateObject("msxml2.xmlhttp")
url = "http://data.eastmoney.com/stock/tradedetail.html"
.Open "get", url, False
.send
html.body.innerhtml = StrConv(.responsebody, vbUnicode)
Cells(1, 2) = html.body.document.getElementById("notice_Ddl").DefaultValue
Set tr = html.all.tags("tr")
j = 1
For r = 0 To tr.Length - 1
If Val(tr(r).Cells(0).innertext) + 1 = j Then
j = j + 1
Cells(j, 1) = tr(r).Cells(0).innertext
Cells(j, 2) = tr(r).Cells(1).innertext
Cells(j, 3) = tr(r).Cells(2).innertext
Cells(j, 4) = tr(r).Cells(6).innertext
Cells(j, 5) = tr(r).Cells(8).innertext
End If
Next
End With
End Sub
这个代码中, .Open "get", url, False,后面的FALSE和用TURE的差别、
html.body.document.getElementById("notice_Ddl").DefaultValue,notice_Ddl是干嘛用的
innertext这个取网页的内容 tr(r).Cells(0).innertext取的是什么位置?
问题二、
Sub 按钮1_单击()
Dim url, html, js
br = [{"序号","代码","名称","交易日期","机构席位买入(万)","机构席位卖出(万)","类型"}]
Range("a1:g1") = br
Set html = CreateObject("htmlfile")
Set js = CreateObject("scriptcontrol")
js.Language = "jscript"
url = "http://datainterface.eastmoney.com/EM_DataCenter/JS.aspx?type=LHB"
url = url & "&sty=JGXWMX"
url = url & "&p=1"
url = url & "&ps=" & 350 '数据1页就是50,7页就是350
url = url & "&js=var%20suwenkai={%22data%22:[(x)],%22pages%22:%22(pc)%22,%22update%22:%22(ud)%22}"
With CreateObject("msxml2.xmlhttp")
.Open "get", url, False
.send
s = .responsetext
js.addcode (s)
slen = js.eval("suwenkai.data.length") - 1
For i = 0 To slen
n = n + 1
ar = Split(js.eval("suwenkai.data[" & i & "]"), ",")
Cells(n + 1, 1) = n
Cells(n + 1, 2) = ar(2)
Cells(n + 1, 3) = ar(4)
Cells(n + 1, 4) = ar(5)
Cells(n + 1, 5) = ar(3)
Cells(n + 1, 6) = ar(1)
Cells(n + 1, 7) = ar(0)
Next
End With
End Sub
代码里面, url 与了那么多次,每行的字符串是怎么来的,怎么用?
特别是url & "&sty=JGXWMX"和url = url & "&js=var%20suwenkai={%22data%22:[(x)],%22pages%22:%22(pc)%22,%22update%22:%22(ud)%22}" 不懂怎么来的、
此外ar = Split(js.eval("suwenkai.data[" & i & "]"), ",") 不懂什么意思
望各位大神解答了,谢谢!实在是看了很久,找了很多资料都不理解。
谢谢!!!!
|
|