Excel精英培训网

 找回密码
 注册
数据透视表40+个常用小技巧,让你一次学会!
查看: 3521|回复: 12

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

[复制链接]
发表于 2013-5-19 20:42 | 显示全部楼层 |阅读模式
fjtc.com.cn/Line-1105
上面是网址,要提取其中红圈里的信息如图。可行吗
QQ图片20130519204139.jpg
最佳答案
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
复制代码
发表于 2013-5-19 20:57 | 显示全部楼层
回复

使用道具 举报

发表于 2013-5-19 20:59 | 显示全部楼层
你最好把网址贴出来。不然大罗神仙也没法帮你解决的。
回复

使用道具 举报

 楼主| 发表于 2013-5-19 21:00 | 显示全部楼层
对的,开奖号的前三位
回复

使用道具 举报

 楼主| 发表于 2013-5-19 21:08 | 显示全部楼层
hwc2ycy 发表于 2013-5-19 20:59
你最好把网址贴出来。不然大罗神仙也没法帮你解决的。

网址有给啊,完整的网址发不出去

www,  fjtc.com.cn/Line-1105
回复

使用道具 举报

发表于 2013-5-19 21:38 | 显示全部楼层
哪个彩,这个应该很容易的。
回复

使用道具 举报

 楼主| 发表于 2013-5-19 21:39 | 显示全部楼层
福建体彩 11选5 前三
回复

使用道具 举报

发表于 2013-5-19 22:04 | 显示全部楼层
本帖最后由 hwc2ycy 于 2013-5-19 22:26 编辑

查这个么?
QQ截图20130519220412.jpg

只要开奖号码和基数吧?
回复

使用道具 举报

发表于 2013-5-19 22:50 | 显示全部楼层
本帖最后由 hwc2ycy 于 2013-5-22 06:44 编辑
  1. Sub 查询福彩()

  2.     Dim strDate$
  3.     Dim strUrl$
  4.     Dim strText$
  5.     Dim strFind$
  6.     Dim arr1, arr2, result()
  7.     Dim i As Long, j As Byte, k As Byte, m As Byte
  8.     Dim httpRequest As Object


  9.     strUrl = "http://www.fjtc.com.cn/Line-1105"

  10.     Set httpRequest = CreateObject("Msxml2.XMLHTTP.3.0")
  11.     With httpRequest
  12.         .Open "GET", strUrl, False
  13.         .send
  14.         strText = .responseText
  15.     End With
  16.     strFind = "<table class=""cpzs_table mt10"">"
  17.     strText = Split(strText, strFind)(1)
  18.     strText = Split(strText, "</table>")(0)
  19.     arr1 = Split(strText, "</tr>")
  20.     m = m + 1
  21.     ReDim result(1 To UBound(arr1), 1 To 6)


  22.     '标题
  23.     result(m, 1) = "期数"
  24.     result(m, 2) = "开奖号码"

  25.     For j = 4 To UBound(arr1)
  26.         If arr1(j) Like "<tr><td>*" Then
  27.             arr2 = Split(arr1(j), "</td>")
  28.             m = m + 1

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

  39.     Application.ScreenUpdating = False
  40.     With Range("a1")
  41.         .CurrentRegion.ClearContents
  42.         .Resize(m, UBound(result, 2)).Value = result
  43.         .CurrentRegion.EntireColumn.AutoFit
  44.     End With
  45.     Application.ScreenUpdating = True
  46.     MsgBox "提取完成"
  47. End Sub
复制代码
回复

使用道具 举报

发表于 2013-5-19 22:53 | 显示全部楼层
本帖最后由 hwc2ycy 于 2013-5-22 06:43 编辑
  1. Sub 查询福彩只查前3期()

  2.     Dim strDate$
  3.     Dim strUrl$
  4.     Dim strText$
  5.     Dim strFind$
  6.     Dim arr1, arr2, result(1 To 4, 1 To 6)
  7.     Dim i As Long, j As Byte, k As Byte, m As Byte
  8.     Dim httpRequest As Object
  9.     Dim myClip As Object
  10.    
  11.     strUrl = "http://www.fjtc.com.cn/Line-1105"

  12.     Set httpRequest = CreateObject("Msxml2.XMLHTTP.3.0")
  13.     With httpRequest
  14.         .Open "GET", strUrl, False
  15.         .send
  16.         strText = .responseText
  17.     End With
  18.     strFind = "<table class=""cpzs_table mt10"">"
  19.     strText = Split(strText, strFind)(1)
  20.     strText = Split(strText, "</table>")(0)
  21.     arr1 = Split(strText, "</tr>")
  22.     m = m + 1
  23.     'ReDim result(1 To UBound(arr1), 1 To 6)

  24.     '标题
  25.     result(m, 1) = "期数"
  26.     result(m, 2) = "开奖号码"

  27.     For j = 4 To 6  'UBound(arr1)
  28.         'If arr1(j) Like "<tr><td>*" Then
  29.             arr2 = Split(arr1(j), "</td>")
  30.             m = m + 1

  31.             '第1列期数
  32.             result(m, 1) = Split(Split(arr1(j), "</td")(0), "<td>")(1)
  33.             '第2列到6列
  34.             For k = LBound(arr2) + 1 To UBound(result, 2) - 1
  35.                 result(m, k + 1) = Split(Split(arr2(k), "<span class=""spNum"">")(1), "<")(0)
  36.             Next
  37.         'Else
  38.         '    Exit For
  39.         'End If
  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.     Application.ScreenUpdating = True
  48.     MsgBox "提取完成"
  49. End Sub
复制代码
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-4-26 19:29 , Processed in 0.381094 second(s), 14 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

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