Excel精英培训网

 找回密码
 注册
数据透视表40+个常用小技巧,让你一次学会!
12
返回列表 发新帖
楼主: demon558

[已解决]请教用EXCEL解析网站的可能性

[复制链接]
 楼主| 发表于 2013-5-20 08:17 | 显示全部楼层
本帖最后由 demon558 于 2013-5-20 15:15 编辑

谢谢老师,辛苦了
我要提取的是所有开奖号中每一期的前三位。。如

期数        开奖号码                                
13051658        9        5        8        3        1
13051659        3        11        6        8        4
13051660        10        5        11        1        8
改成下面这样
期数        开奖号码               
13051658        9        5        8
13051659        3        11        6
13051660        10        5      

另外也要全部每一期5个号

所有数据指 从fjtc.com.cn/Line-1105到fjtc.com.cn/Line-1105?Page=4的号码
是我没说清楚,不好意思

excel精英培训的微信平台,每天都会发送excel学习教程和资料。扫一扫明天就可以收到新教程
回复

使用道具 举报

 楼主| 发表于 2013-5-20 15:19 | 显示全部楼层
回复

使用道具 举报

发表于 2013-5-22 06:57 | 显示全部楼层    本楼为最佳答案   
  1. Sub 查询福彩前4页()

  2.     Dim strDate$
  3.     Dim strUrl$
  4.     Dim strText$
  5.     Dim strFind$
  6.     Dim arr1, arr2, result(1 To 400, 1 To 6)
  7.     Dim i As Long, j As Byte, k As Byte, m As Integer
  8.     Dim httpRequest As Object
  9.     Dim btPage As Byte
  10.     m = 1
  11.     '标题
  12.     result(m, 1) = "期数"
  13.     result(m, 2) = "开奖号码"

  14.     For btPage = 1 To 4

  15.         strUrl = "http://fjtc.com.cn/Line-1105?Page=" & btPage
  16.         Set httpRequest = CreateObject("Msxml2.XMLHTTP.3.0")
  17.         With httpRequest
  18.             .Open "GET", strUrl, False
  19.             .send
  20.             strText = .responseText
  21.         End With

  22.         strFind = "<table class=""cpzs_table mt10"">"
  23.         strText = Split(strText, strFind)(1)
  24.         strText = Split(strText, "</table>")(0)
  25.         arr1 = Split(strText, "</tr>")

  26.         For j = 4 To UBound(arr1)
  27.             If arr1(j) Like "<tr><td>*" Then
  28.                 arr2 = Split(arr1(j), "</td>")
  29.                 m = m + 1
  30.                 '第1列期数
  31.                 result(m, 1) = Split(Split(arr1(j), "</td")(0), "<td>")(1)
  32.                 '第2列到6列
  33.                 For k = LBound(arr2) + 1 To UBound(result, 2) - 1
  34.                     result(m, k + 1) = Split(Split(arr2(k), "<span class=""spNum"">")(1), "<")(0)
  35.                 Next
  36.             Else
  37.                 Exit For
  38.             End If
  39.         Next
  40.     Next

  41.     Application.ScreenUpdating = False

  42.     With Range("a1")
  43.         .CurrentRegion.ClearContents
  44.         .Resize(m, UBound(result, 2)).Value = result
  45.         .CurrentRegion.EntireColumn.AutoFit
  46.     End With
  47.     Range("B1:F1").HorizontalAlignment = xlCenterAcrossSelection

  48.     Application.ScreenUpdating = True
  49.     MsgBox "提取完成"
  50. End Sub
复制代码
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|Archiver|Excel精英培训 ( 豫ICP备11015029号 )

GMT+8, 2024-5-6 18:50 , Processed in 0.218635 second(s), 8 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表