ExcelTip.Net留存知识帖 ---【注:附件之前被网盘供应商清空后,现已修复-现已修复-现已修复为本地下载!】
现在位置:首页 > 我的酷贴 > Excel VBA > 如何使用webbrowser下载网页数据(多页)

如何使用webbrowser下载网页数据(多页)

作者:绿色风 分类: 时间:2022-08-18 浏览:88
楼主
xmyjk
Q:如何获取网页:
(原提问帖至17楼开始,已经是另外一个问题的提问了,且回答方式也是与前贴截然不同的,由XMLHTTP转至WEBBROWSR方式回答,特此再次采集。)

A:由于该页面使用XMLHTTP+数组采集的数据,数据会出现错位,且返回的是/U****的四角码,因此不采用XMLHTTP方式续作网页采集,采用WEBBROWSER的方式操作。
  1. Option Explicit
  2. Sub a()
  3. Dim ie1 As Object, dmt As Object, r As Object, i As Long, j As Long, n As Long, p As Long

  4. 'Load UserForm1
  5. 'UserForm1.Show 0
  6. On Error Resume Next

  7. [a1].CurrentRegion.Offset(1).Clear
  8. Cells.NumberFormat = "@"
  9. Set ie1 = UserForm1.WebBrowser1

  10. With ie1
  11.   .Navigate "http://stock.jrj.com.cn/report/yjyg.shtml" '网址
  12.   Do Until .ReadyState = 4 And InStr(.Document.body.innertext, "行情 资讯 股吧") > 0
  13.     DoEvents
  14.   Loop
  15.   Set dmt = .Document
  16. End With

  17. Set r = dmt.All.tags("table")(1).Rows
  18. For i = 0 To r.Length - 1
  19.    For j = 0 To r(i).Cells.Length - 1
  20.        Cells(i + 2, j + 1) = r(i).Cells(j).innertext
  21.    Next
  22. Next
  23. Set dmt = Nothing
  24. Set r = Nothing

  25. For p = 2 To 3 ' 23
  26.    With ie1
  27.       .Navigate "javascript:myNiceTable.goPage(" & p & ");"
  28.       Do Until Val(.Document.All.tags("table")(1).Rows(0).Cells(0).innertext) = (p - 1) * 50 + 1
  29.         DoEvents
  30.       Loop
  31.       Set dmt = .Document
  32.    End With

  33.    Set r = dmt.All.tags("table")(1).Rows
  34.    n = [a65536].End(3).Row + 1
  35.    For i = 0 To r.Length - 1
  36.       For j = 0 To r(i).Cells.Length - 1
  37.           Cells(i + n, j + 1) = r(i).Cells(j).innertext
  38.       Next
  39.    Next
  40.    Set dmt = Nothing
  41.    Set r = Nothing

  42. Next

  43. Set ie1 = Nothing

  44. [a1].CurrentRegion.Columns.AutoFit

  45. MsgBox "ok!"

  46. End Sub

使用WEBBROWSER下载网页数据.rar
2楼
清华
看了附件我受到启发 
3楼
老肥
非常好,有个问题,希望你能帮我解决,
QQ:236715227
4楼
水星钓鱼
学习

免责声明

有感于原ExcelTip.Net留存知识的价值及部分知识具有的时间限定性因素, 经与ExcelTip.Net站长Apolloh商议并征得其同意, 现将原属ExcelTip.Net的知识帖采集资料于本站点进行展示, 供有需要的人士查询使用,也慰缅曾经的论坛时代。 所示各个帖子的原作者如对版权有异议, 可与本人沟通提出,或于本站点留言,我们会尽快处理。 在此,感谢ExcelTip.Net站长Apolloh的支持,感谢本站点所有人**绿色风(QQ:79664738)**的支持与奉献,特此鸣谢!
------本人网名**KevinChengCW(QQ:1210618015)**原ExcelTip.Net总版主之一

评论列表
sitemap