返回列表 上一主題 發帖

[發問] 上市個股日成交資訊下載改版建議

回復 19# jsleee

我找到的方法是網頁上有download html網頁的按鈕,
按下去新開的網頁網址就是了,
硬是看了半天網頁程式碼,才發現原來按一下就有結果了

TOP

網址有了

自己練習看看
joey0415 發表於 2017-5-24 21:35

請教一下,字型跟大小如何控制??

TOP

回復 21# prin.huang


    了解
    感謝你

JS

TOP

回復  prin.huang

網址有了

自己練習
joey0415 發表於 2017-5-24 21:38


請教下面這個網址這麼抓?
http://www.tse.com.tw/zh/page/trading/fund/BFI82U.html

TOP

TOP

回復  t8899


自己練習看看
joey0415 發表於 2017-6-3 20:50

感謝指導

TOP

您好
請問以下這個期貨交易資訊的網頁,若要透過程式碼來抓取不同日期的資料,該如何處理?
再麻煩先進們指點,謝謝
http://www.taifex.com.tw/chinese/3/7_12_1.asp

TOP

回復 27# jsleee
自己寫的function給你參考,會回傳一個string陣列
  1. Private Function GetWebTb1(sURL00$, nTT00%, nRR00%, nCC00%, bRd00 As Boolean)
  2. '===sURL00      為擷取網址
  3. '===nTT00       為讀取第幾個Table(從1開始)
  4. '===nRR00       該Table由第幾列開始讀取(從1開始)
  5. '===nCC00       該Table由第幾欄開始讀取(從1開始)
  6. '===bRd00       該資料是否輸出
  7. Dim nR00%, nC00%, sTemp() As String, oXml As Object, oDoc As Object, oE As Object, tt As Date
  8.     Set oXml = CreateObject("MSXML2.XMLHTTP.6.0")
  9.     Set oDoc = CreateObject("HTMLFile")
  10.     bRd00 = True
  11. rSend:
  12.     tt = Now() + TimeValue("0:00:20")
  13.     With oXml
  14.         .Open "Get", sURL00, True
  15.         .setRequestHeader "Content-type", "application/x-www-form-urlencoded"
  16.         .send
  17.         On Error Resume Next
  18.         Do While .ReadyState <> 4 Or .Status <> 200
  19.             DoEvents
  20.             If Now > tt Then GoTo rSend
  21.         Loop
  22.         On Error GoTo 0
  23.         oDoc.write .responseText
  24.     End With
  25.     If oDoc.all.tags("Table")(nTT00 - 1) Is Nothing Then bRd00 = False: GoTo Err1
  26.     Set oE = oDoc.all.tags("Table")(nTT00 - 1)
  27.     With oE
  28.         ReDim sTemp(.Rows.Length - nRR00, .Rows(nRR00 - 1).Cells.Length - nCC00)
  29.         For nR00 = 0 To .Rows.Length - nRR00
  30.             For nC00 = 0 To .Rows(nR00 + nRR00 - 1).Cells.Length - nCC00
  31.                 sTemp(nR00, nC00) = .Rows(nR00 + nRR00 - 1).Cells(nC00 + nCC00 - 1).innerText
  32.             Next nC00
  33.         Next nR00
  34.     End With
  35. Err1:
  36.     GetWebTb1 = sTemp
  37.     oXml.abort
  38.     oDoc.Close
  39.     Set oXml = Nothing
  40.     Set oDoc = Nothing
  41.     Set oE = Nothing
  42. End Function
複製代碼

TOP

回復 28# prin.huang


    不好意思
    請問 prin.huang 先進
    這個Function 要如何運用?

TOP

回復 29# jsleee
假設要抓http://www.twse.com.tw/exchangeReport/MI_INDEX?response=html&date=20170609&type=MS
這網頁的第一個表,從第二列開始抓
(因程式判斷欄位矩陣宣告靠要抓取的第一列有幾個欄位, 若要從第一列開始抓, 你自己要再改一下)
寫一段程式給function需要的資訊,再把function傳回的資料,輸出到excel活頁表,參考如下
  1. Sub main()
  2. Dim URL$, VV As Boolean, AB() As String

  3. URL = "http://www.twse.com.tw/exchangeReport/MI_INDEX?response=html&date=20170609&type=MS"
  4. AB = GetWebTb1(URL, 1, 2, 1, VV)
  5. If VV = True Then ActiveSheet.Range("A1:E63") = AB

  6. End Sub

  7. Private Function GetWebTb1(sURL00$, nTT00%, nRR00%, nCC00%, bRd00 As Boolean)
  8. '===sURL00      為擷取網址
  9. '===nTT00       為讀取第幾個Table(從1開始)
  10. '===nRR00       該Table由第幾列開始讀取(從1開始)
  11. '===nCC00       該Table由第幾欄開始讀取(從1開始)
  12. '===bRd00       該資料是否輸出
  13. Dim nR00%, nC00%, sTemp() As String, oXml As Object, oDoc As Object, oE As Object, tt As Date
  14.     Set oXml = CreateObject("MSXML2.XMLHTTP.6.0")
  15.     Set oDoc = CreateObject("HTMLFile")
  16.     bRd00 = True
  17. rSend:
  18.     tt = Now() + TimeValue("0:00:20")
  19.     With oXml
  20.         .Open "Get", sURL00, True
  21.         .setRequestHeader "Content-type", "application/x-www-form-urlencoded"
  22.         .send
  23.         On Error Resume Next
  24.         Do While .ReadyState <> 4 Or .Status <> 200
  25.             DoEvents
  26.             If Now > tt Then GoTo rSend
  27.         Loop
  28.         On Error GoTo 0
  29.         oDoc.write .responseText
  30.     End With
  31.     If oDoc.all.tags("Table")(nTT00 - 1) Is Nothing Then bRd00 = False: GoTo Err1
  32.     Set oE = oDoc.all.tags("Table")(nTT00 - 1)
  33.     With oE
  34.         ReDim sTemp(.Rows.Length - nRR00, .Rows(nRR00 - 1).Cells.Length - nCC00)
  35.         For nR00 = 0 To .Rows.Length - nRR00
  36.             For nC00 = 0 To .Rows(nR00 + nRR00 - 1).Cells.Length - nCC00
  37.                 sTemp(nR00, nC00) = .Rows(nR00 + nRR00 - 1).Cells(nC00 + nCC00 - 1).innerText
  38.             Next nC00
  39.         Next nR00
  40.     End With
  41. Err1:
  42.     GetWebTb1 = sTemp
  43.     oXml.abort
  44.     oDoc.Close
  45.     Set oXml = Nothing
  46.     Set oDoc = Nothing
  47.     Set oE = Nothing
  48. End Function
複製代碼

TOP

        靜思自在 : 虛空有盡.我願無窮,發願容易行願難。
返回列表 上一主題