返回列表 上一主題 發帖

[發問] 抓取網頁資料(彈出式視窗)

回復 1# PKKO

  1. Sub ex1()

  2.     For i = 1 To 30
  3.      
  4.         Cells(i, 4) = Len(Cells(i, 3))
  5.         Cells(i, 5) = InStr(Cells(i, 3), "(")
  6.         Cells(i, 6) = InStr(Cells(i, 3), ")")
  7.         Cells(i, 7) = Mid(Cells(i, 3), Cells(i, 5) + 2, Cells(i, 6) - Cells(i, 5) - 3) '公司代碼

  8.         snum = Cells(i, 7)
  9.         Set HTML = CreateObject("htmlfile")
  10.         
  11.         Dim strText As String
  12.         With CreateObject("WinHttp.WinHttpRequest.5.1")
  13.             .Open "get", "http://www.travel.org.tw/showtable.aspx?id=" & snum, False
  14.             .Send
  15.             strText = .responseText
  16.             
  17.             HTML.body.innerhtml = strText
  18.             Set tb = HTML.all.tags("table")(0).Rows
  19.             
  20.             For x = 1 To 13
  21.                 Cells(i, x + 7) = tb(x).Cells(1).innertext
  22.             Next
  23.         End With

  24.     Next
  25.         
  26.     Cells.EntireColumn.AutoFit
  27. End Sub
複製代碼
test.zip (27.6 KB)

TOP

        靜思自在 : 犯錯出懺悔心,才能清淨無煩惱。
返回列表 上一主題