返回列表 上一主題 發帖

[發問] 使用 msXML2.xmlHTTP 取得股票交易資料

[發問] 使用 msXML2.xmlHTTP 取得股票交易資料

請問大師前輩如何以 xmlhttp 的方法取得網頁中如下圖的資料:
  1. Sub WebData()
  2.     Dim strURL$
  3.     Dim respAA
  4.     strURL = "https://tw.stock.yahoo.com/q/q?s=2330" '網頁地址
  5.     [A1].CurrentRegion = ""
  6.     Dim oXmlhttp As Object, oHtmldoc As Object
  7.     Set oXmlhttp = CreateObject("msxml2.xmlhttp")
  8.     Set oHtmldoc = CreateObject("htmlfile")
  9.     With oXmlhttp
  10.         .Open "Get", strURL, False
  11.         .send
  12.         
  13.         '-------------------------------------------------
  14.         '如何取得網頁中的表格資料?
  15.         '及 表格中 第3欄第2列資料?
  16.         '-------------------------------------------------
  17.         
  18.         
  19.     End With
  20. End Sub
複製代碼
非常感恩

回復 1# Scott090


請問那一位高手願意協助

網頁地址如下:l   
https://tw.stock.yahoo.com/q/q?s=2330

謝謝

TOP

回復 3# prin.huang


    非常感恩
提供的code 足當一個 sample, 將好好的研讀,不解之處再請益就教

再次的謝謝

TOP

回復 5# GBKEE


    太好了,又得到超級版主的大作
自當好好的研習

感謝

TOP

回復 3# prin.huang

Sub main() 作修飾如下,請參考
  1. Sub main()
  2. Dim URL$, VV As Boolean, AB() As String

  3. URL = "https://tw.stock.yahoo.com/q/q?s=2330"

  4. 'AB = GetWebTb1(URL, 6, 1, 1, VV)
  5. 'If VV = True Then ActiveSheet.Range("A1") = AB

  6. AB = GetWebTb1(URL, 7, 1, 1, VV)    '目標表格由1開始計算是第7個
  7. If VV = True Then ActiveSheet.Range("A1").Resize(UBound(AB, 1) + 1, UBound(AB, 2) + 1) = AB     'AB陣列放入工作表儲存格

  8. End Sub
複製代碼

TOP

回復 8# prin.huang


    用 QueryTables的方式攫取網頁資料,錄製程式碼,
程式碼內 .WebTables = "7" 就是由1算起排行第7個表格
  1. Sub 巨集1()
  2. '
  3. ' 巨集1 巨集
  4. '

  5. '
  6.     With ActiveSheet.QueryTables.Add(Connection:= _
  7.         "URL;https://tw.stock.yahoo.com/q/q?s=2330", Destination:=Range("$A$1"))
  8.         .Name = "q?s=2330_1"
  9.         .FieldNames = True
  10.         .RowNumbers = False
  11.         .FillAdjacentFormulas = False
  12.         .PreserveFormatting = True
  13.         .RefreshOnFileOpen = False
  14.         .BackgroundQuery = True
  15.         .RefreshStyle = xlInsertDeleteCells
  16.         .SavePassword = False
  17.         .SaveData = True
  18.         .AdjustColumnWidth = True
  19.         .RefreshPeriod = 0
  20.         .WebSelectionType = xlSpecifiedTables
  21.         .WebFormatting = xlWebFormattingNone
  22.         .WebTables = "7"            '顯示所要的資料表格是第7個
  23.         .WebPreFormattedTextToColumns = True
  24.         .WebConsecutiveDelimitersAsOne = True
  25.         .WebSingleBlockTextImport = False
  26.         .WebDisableDateRecognition = False
  27.         .WebDisableRedirections = False
  28.         .Refresh BackgroundQuery:=False
  29.     End With
  30.     ActiveWorkbook.Connections("連線").Delete
  31. End Sub
複製代碼
以上,請參考
謝謝

TOP

發現這個網站很精彩,主題是:
"ImportXML, GoogleLookup alternatives for Excel"
http://www.ideativi.it/blog/532/importxml_googlelookup_alternatives_for_excel.aspx

內含一個EXCEL檔可供參考:
" •16/09/2013 importxml.1.10.xlsx (first public release)"

以上分享

TOP

        靜思自在 : 口說一句好話,如口出蓮花;口說一句壞話如口吐毒蛇。
返回列表 上一主題