|
楼主 |
发表于 2018-8-16 19:31
|
显示全部楼层
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
本帖最后由 谢礼军 于 2018-8-16 20:04 编辑
Sub gedata()
Dim ie As Object, http As Object, dom As Object, win As Object, strtext As String
Dim url As String, arr, i&, k&, brr(), stock As String
Set http = CreateObject("msxml2.xmlhttp")
Set dom = CreateObject("htmlfile")
Set win = dom.parentwindow
UserName = "cqgytyy"
Password = "123456"
With http
.Open "post", "http://fdm.yyjzt.com/user/topLogin.json", False
.setrequestheader "content-type", "application/x-www-form-urlencoded;charset=UTF-8"
.send "jzt_username=" & UserName & "&jzt_password=" & Password
dom.write "<script src=""http://ajax.microsoft.com/ajax/jquery/jquery-1.4.min.js""></script><body></body>"
For Page = 1 To 1 '抓取2页
url = "http://fdm.yyjzt.com/search/merchandise.htm?keyword&category&page=" & Page
.Open "GET", url, False
.send
Do
DoEvents
Loop Until .Status = 200
arr = Split(.responsetext, "<table")
For i = 1 To UBound(arr)
dom.body.innerhtml = "<table>" & Split(arr(i), "</table>")(0) & "</table>"
k = k + 1: ReDim Preserve brr(1 To 7, 1 To k)
brr(1, k) = win.eval("$('a').contents().filter(function(){return this.nodeType==3;}).text()")
brr(2, k) = win.eval("$('td a span.u_goods_spec').eq(0).text()")
brr(3, k) = win.eval("$('td p.u_goods_com').eq(0).text()")
brr(4, k) = win.eval("$('td span.u_goods_pric').eq(0).text()")
brr(5, k) = win.eval("$('td p span.m_tag_kw').eq(1).text()")
stock = Split(Split(arr(i - 1), "u_goods_txt"">")(1), "<")(0)
brr(6, k) = re(stock)
brr(7, k) = win.eval("$('a) p class.u_goods_txt').eq(0).text()")
Next
Application.Wait (Now + TimeValue("0:00:05")) '休息10秒
Next
[a1:g1] = [{"药品名称","规格","厂家","销售价格","件装","库存","效期"}]
[a2].Resize(k, 7) = Application.Transpose(brr)
[a:g].EntireColumn.AutoFit
End With
End Sub
Function re(str)
With CreateObject("vbscript.regexp")
.Pattern = "\s+"
.Global = True
re = .Replace(str, "")
End With
End Function
范老师你好, 领导又要求抓取有效期,我按照你的代码 找到网页的源代码,找到语句,brr(7, k) = win.eval("$('a) p class.u_goods_txt').eq(0).text()")就是我加上去的,麻烦你看看哪儿出错了 谢谢你,范老师。
|
|