返回列表 上一主題 發帖

怎麼篩選所需要的資料

回復 1# Jared
你要抓取的是網頁的資料
  1. Option Explicit
  2. Sub Ex() '抓取ID
  3.     Dim URL As String, a As Object, e As Object, i
  4.     URL = "http://forum.twbts.com/thread-12514-1-1.html"
  5.     'URL = "http://你的網頁"
  6.     With CreateObject("InternetExplorer.Application")
  7.         .Navigate URL
  8.         .Visible = True
  9.         Do While .Busy Or .ReadyState <> 4:         Loop
  10.         Set a = .Document.all
  11.         With ThisWorkbook.Sheets(1)
  12.             .Cells = ""
  13.             On Error Resume Next
  14.             For Each e In a
  15.                 If e.ID <> "" Then
  16.                     i = i + 1
  17.                     .Cells(i, "a") = e.TAGNAME
  18.                     .Cells(i, "B") = e.ID
  19.                     .Cells(i, "C") = e.innertext  '網頁上的文字
  20.                 End If
  21.             Next
  22.         End With
  23.         .Quit
  24.     End With
  25. End Sub
  26. Sub Ex1() '抓取stroke=
  27.     Dim SP As Variant, i As Integer
  28.     URL = "http://你的網頁"
  29.     With CreateObject("Microsoft.XMLHTTP")
  30.         .Open "get", URL, False
  31.        .send
  32.         SP = Split(.responseText, "stroke=""")
  33.     End With
  34.     With ThisWorkbook.Sheets(2)
  35.         .Cells = ""
  36.         For i = 1 To UBound(SP)
  37.             .Cells(i, "A") = Mid(SP(i), 1, InStr(SP(i), """") - 1)
  38.         Next
  39.     End With
  40. End Sub
複製代碼
感恩的心......(在麻辣家族討論區.用心學習會有進步的)
但資源無限,後援有限,  一天1元的贊助,人人有能力.

TOP

        靜思自在 : 人要自愛,才能愛普天下的人。
返回列表 上一主題