|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
本帖最后由 jpj123 于 2015-10-24 21:46 编辑
最近学习网抓,借鉴各位老师的代码写获取1-8页的!
- Sub HomerWork1_3()
- '新手:jpj123
- '作业:1、网站:http://data.bank.hexun.com/lccp/jrxp.aspx
- ' 操作:点击“今日在售产品”,获取今日在售产品第1-8页的数据。
- Dim xml, url As String, St As String
- Dim arr, brr, ar, i%, r%, html, Db, tr, td, n%, L%, j%, a%
- ActiveSheet.Cells.Clear
- For L = 1 To 8
- url = "http://data.bank.hexun.com/lccp/Jrxp.aspx?col=1&tag=desc&date=2014-10-21&page=" & L
- Set xml = CreateObject("MSXML2.XMLHTTP")
- Set html = CreateObject("htmlfile")
- With xml
- .Open "GET", url, False
- .send
- St = .responseText
- End With
- St = Split(Split(St, "<div class=""mark"">")(1), "</div>")(0)
- html.body.innerhtml = St
- Set Db = html.all.tags("table")
- n = ActiveSheet.UsedRange.Rows.Count
- If L = 1 Then a = 0: n = n - 1 Else a = 1
- For i = a To Db(0).Rows.Length - 1
- Set tr = Db(0).Rows(i)
- n = n + 1: j = 0
- For Each td In tr.Cells
- j = j + 1
- If j >= 2 Then ActiveSheet.Cells(n, j - 1) = td.innertext
- Next
- Next
- Next
- MsgBox "成功获取网页数据!"
- End Sub
复制代码 |
评分
-
1
查看全部评分
-
|