返回列表 上一主題 發帖

上櫃 個股日成交資訊 抓取問題

回復 1# espionage
試試看
  1. With CreateObject("InternetExplorer.Application") '開啟證券櫃臺買賣中心網頁
  2.         .Visible = True
  3.         .Navigate "http://www.tpex.org.tw/web/stock/aftertrading/daily_trading_info/st43.php?l=zh-tw"
  4.         Do While .Busy Or .ReadyState <> 4: DoEvents: Loop
  5.         With .document
  6.             .getElementsByTAGName("INPUT")("input_stock_code").Value = stockcode
  7.             '--------------------輸入要查詢的日期
  8.             With .getElementsByTAGName("INPUT")("input_date")
  9.                 .Value = yearmonth
  10.                 '*********************
  11.                 .fireEvent ("onchange") 'ie8可用
  12.                 '新版ie 請參考 http://forum.twbts.com/thread-14308-1-1.html
  13.                 '**********************
  14.             End With
  15.         End With
  16.     End With
複製代碼
感恩的心......(在麻辣家族討論區.用心學習會有進步的)
但資源無限,後援有限,  一天1元的贊助,人人有能力.

TOP

回復 3# espionage
不錯是要等待網頁的資料下載完畢
  1. Option Explicit
  2. Sub Ex()
  3.     Dim a As Object, stockcode
  4.     With CreateObject("InternetExplorer.Application") '開啟證券櫃臺買賣中心網頁
  5.         .Visible = True
  6.         stockcode = 4111
  7.         .Navigate "http://www.tpex.org.tw/web/stock/aftertrading/daily_trading_info/st43.php?l=zh-tw"
  8.         Do While .Busy Or .readyState <> 4: DoEvents: Loop
  9.         With .Document
  10.             .getElementsByTAGName("INPUT")("input_stock_code").Value = stockcode
  11.             '--------------------輸入要查詢的日期
  12.             With .getElementsByTAGName("INPUT")("input_date")
  13.                 .Value = "104/06" ' yearmonth
  14.                 '*********************
  15.                 .fireEvent ("onchange") 'ie8可用
  16.                 '新版ie 請參考 http://forum.twbts.com/thread-14308-1-1.html
  17.                 '**********************
  18.             End With
  19.             With .getElementByID("stk_no")
  20.                 Do
  21.                     If .INNERTEXT = "請輸入股票代碼及資料年月" Then
  22.                         MsgBox "請輸入股票代碼及資料年月"
  23.                         GoTo ER
  24.                     End If
  25.                 Loop Until InStr(.INNERTEXT, stockcode)
  26.             End With
  27.             Set a = .getElementsByTAGName("table")
  28.             MsgBox .getElementByID("stk_no").INNERTEXT & vbLf & a(0).outertext
  29.         End With
  30. ER:
  31.         .Quit
  32.     End With
  33. End Sub
複製代碼
感恩的心......(在麻辣家族討論區.用心學習會有進步的)
但資源無限,後援有限,  一天1元的贊助,人人有能力.

TOP

        靜思自在 : 不要隨心所欲,要隨心教育自己。
返回列表 上一主題