返回列表 上一主題 發帖

[發問] 如何寫excel VBA去抓取網頁原始碼內的特定文字

回復 2# daniel1326
  1. Option Explicit
  2. Function Mp3(Word As String) As String
  3.     Dim Url As String, Ar
  4.     Url = "http://dictionary.reference.com/browse/" & Word & "?s=b"
  5.     If Word = "" Then Mp3 = "??": Exit Function
  6.     With CreateObject("Microsoft.XMLHTTP")
  7.         .Open "get", Url, False
  8.        .send     
  9.         Ar = Split(Split(UCase(.responseText), ".MP3")(1), "/")
  10.         Mp3 = Ar(UBound(Ar))
  11.    End With
  12. End Function
複製代碼

TOP

回復 5# ui123
請說明:抓這網頁哪裡的資料
  1. Option Explicit
  2. 'Sub Ex()
  3.     Dim Url As String, AR
  4.     Url = "https://finance.yahoo.com/quote/AAPL?p=AAPL"
  5.     With CreateObject("Microsoft.XMLHTTP")
  6.         .Open "get", Url, False
  7.        .send
  8.         If InStr(.responseText, "CrumbStore"":{""crumb"":""") = False Then MsgBox "找不到啊"
  9.         
  10.    End With
  11. End Sub
複製代碼
感恩的心......(在麻辣家族討論區.用心學習會有進步的)
但資源無限,後援有限,  一天1元的贊助,人人有能力.

TOP

回復 9# ui123
Java 語言尚未入門,幫不上忙
只抓到100筆資料
  1. Sub Ex()
  2.     Dim oXmlhttp As Object, oHtmldoc As Object, surl, r, c, E
  3.     Set oXmlhttp = CreateObject("msxml2.xmlhttp")
  4.     Set oHtmldoc = CreateObject("htmlfile")
  5.     surl = "https://finance.yahoo.com/quote/AAPL/history?period1=1473638400&period2=1505174400&interval=1d&filter=history&frequency=1d"
  6.     With oXmlhttp
  7.         .Open "Get", surl, False
  8.         .Send
  9.         oHtmldoc.write .responseText
  10.     End With
  11.      With oHtmldoc
  12.         Set E = .all.tags("table")(3)
  13.         ActiveSheet.Cells.Clear
  14.         For r = 0 To E.Rows.Length - 1
  15.             For c = 0 To E.Rows(r).Cells.Length - 1
  16.                 Cells(r + 1, c + 1) = E.Rows(r).Cells(c).innertext
  17.             Next
  18.         Next
  19.     End With
  20.     Set oXmlhttp = Nothing
  21.     Set oHtmldoc = Nothing
  22. End Sub
複製代碼
感恩的心......(在麻辣家族討論區.用心學習會有進步的)
但資源無限,後援有限,  一天1元的贊助,人人有能力.

TOP

        靜思自在 : 待人退一步,愛人寬一寸,就會活得很快樂。
返回列表 上一主題