|
Sub 杏仁_淘宝搜索()
On Error Resume Next
Dim searchname As String
Set oDoc = CreateObject("htmlfile")
Columns("A:A").NumberFormatLocal = "@"
searchname = "杏仁" '%D0%D3%C8%CA
qst = encodeURI(searchname)
riqi = Format(Now, "yyyymmdd")
[a1:f1] = Split("货名、每半斤多少元、净含量、物流运费、最近成交、评价等信息", "、")
With CreateObject("WinHttp.WinHttpRequest.5.1")
For p = 1 To 100
n = Range("a65536").End(xlUp).Row
.Open "POST", "http://s.taobao.com/search?q=" & qst & "&initiative_id=tbindexz_" & riqi & "&commend=all&ssid=s5-e&search_type=item&sourceId=tb.index&bcoffset=1&newpre=null&s=" & (p - 1) * 40, False
.SetRequestHeader "Referer", "http://www.taobao.com/"
.SetRequestHeader "Connection", "Keep-Alive"
.send
tt = Split(Split(.responsetext, "data-item-count=""40"">")(1), "<!-- end list view -->")(0)
oDoc.body.innerHTML = tt
Set r = oDoc.All.tags("li")
m = 0
For i = 0 To r.Length - 1
If r(i).classname = "list-item" Then
m = m + 1
't1 = Split(r(i).All.tags("a")(0).Title, "杏仁")
Cells(n + m, 1) = r(i).All.tags("a")(0).Title '货名
Cells(n + m, 2) = r(i).All.tags("em")(1).innerText & "元/" & r(i).All.tags("em")(2).innerText '每半斤多少元
'Cells(n + m, 3) = t1(UBound(t1)) '净含量
Cells(n + m, 4) = Split(r(i).All.tags("li")(1).innerText, ":")(1) '物流运费
Cells(n + m, 5) = Split(r(i).All.tags("li")(0).innerText, "最近成交")(1) '最近成交
Cells(n + m, 6) = "http://rate.tmall.com/list_detail_rate.htm?itemId=" & Split(r(i).All.tags("a")(0).href, "id=")(1) & "¤tPage=1" '评价等信息
End If
Next i
Next p
End With
End Sub
Function encodeURI(becoded As String) As String 'url编码
Set JS = CreateObject("msscriptcontrol.scriptcontrol")
JS.Language = "JavaScript"
encodeURI = JS.Eval("encodeURIComponent('" & becoded & "');")
End Function |
|