返回列表 上一主題 發帖

交易明細下載

交易明細下載

http://bsr.twse.com.tw/bshtm/

這個網站比較有人性一點  參數找的到也可以設定

但是我不知道頁數有幾張

土法煉鋼一頁一頁弄也很沒有效率

查詢太多次還會被檔

請問程式該如何下載
  1. Sub 個股交易明細下載()
  2.     Dim 股票代號 As String, 日期 As Variant, N, i As Integer, A, T As Date
  3.     Do While Not IsDate(日期)
  4.         日期 = InputBox("輸入查詢日期", "日期", Date)
  5.         If 日期 = "" Then End
  6.     Loop
  7.     Do While 股票代號 = ""
  8.         股票代號 = InputBox("股票代號", "輸入查詢之股票代號", "1101")
  9.         If 日期 = "" Then End
  10.     Loop
  11.     日期 = Format(日期, "yyyymmdd")
  12.     T = Time
  13.     With ActiveSheet
  14.         For Each N In .Names
  15.             N.Delete
  16.         Next
  17.         .Cells.Clear
  18.         Application.StatusBar = False
  19.         On Error GoTo A_Wait
  20.         With .QueryTables.Add(Connection:="URL;http://bsr.twse.com.tw/bshtm/bshtm_report_Messages.aspx?strDate=" & 日期 & "&StartNumber=" & 股票代號 & "&FocusIndex=1", Destination:=Range("A1"))
  21.             .Name = 日期 & "_" & 股票代號 & "_1"
  22.             .FieldNames = True
  23.             .RowNumbers = False
  24.             .FillAdjacentFormulas = False
  25.             .PreserveFormatting = True
  26.             .RefreshOnFileOpen = False
  27.             .BackgroundQuery = True
  28.             .RefreshStyle = xlInsertDeleteCells
  29.             .SavePassword = False
  30.             .SaveData = True
  31.             .AdjustColumnWidth = True
  32.             .RefreshPeriod = 0
  33.             .WebSelectionType = xlEntirePage
  34.             .WebFormatting = xlWebFormattingNone
  35.             .WebPreFormattedTextToColumns = True
  36.             .WebConsecutiveDelimitersAsOne = True
  37.             .WebSingleBlockTextImport = False
  38.             .WebDisableDateRecognition = False
  39.             .WebDisableRedirections = False
  40.             .Refresh BackgroundQuery:=False
  41.             If Application.CountA(.ResultRange) = 0 Then
  42.                 MsgBox Format(日期, "0000/00/00") & " 休市!!!  或  股票代號:" & 股票代號 & " 錯誤 !!!"
  43.                 [A1].Select
  44.                 End
  45.             End If
  46.         End With
  47.         i = 2
  48.         Do
  49.             .Cells(Rows.Count, 1).End(xlUp).Offset(1).Select
  50.             With .QueryTables.Add(Connection:="URL;http://bsr.twse.com.tw/bshtm/bshtm_report_Messages.aspx?strDate=" & 日期 & "&StartNumber=" & 股票代號 & "&FocusIndex=" & i, Destination:=Selection)
  51.                 .Name = 日期 & "_" & 股票代號 & "_" & i
  52.                 .WebSelectionType = xlSpecifiedTables
  53.                 .WebFormatting = xlWebFormattingNone
  54.                 .WebTables = "6"
  55.                 .WebPreFormattedTextToColumns = True
  56.                 .WebConsecutiveDelimitersAsOne = True
  57.                 .WebSingleBlockTextImport = False
  58.                 .WebDisableDateRecognition = False
  59.                 .WebDisableRedirections = False
  60.               ''''''無法查詢時稍待  到  A_Wait: '''''
  61.                 .Refresh BackgroundQuery:=False
  62.                 If Application.CountA(.ResultRange) = 0 Then GoTo Out
  63.                 i = i + 1
  64.             End With
  65.             A = CreateObject("WScript.Shell").popup("請等後下載..." & Chr(10) & Chr(10) & "** 請勿按下 ** [確定]", 4, 日期 & "_" & .[F2] & "  第" & i & "頁", 16 * 3 + 0)
  66.             Application.ScreenUpdating = True
  67.         Loop
  68. Out:
  69.         .UsedRange.Columns.AutoFit
  70.         .[A1].Select
  71.         A = CreateObject("WScript.Shell").popup("共下載" & i & "頁", 5, 日期 & "_" & 股票代號, 48 + 0)
  72.         Application.StatusBar = "共下載 " & i & "頁 費時 " & Format(Time - T, "HH:MM:SS")
  73.     End With
  74.     End
  75. A_Wait:
  76.     Application.StatusBar = "無法查詢等候10秒鐘"
  77.     Application.Wait Now + TimeValue("00:00:10")
  78.     Err.Clear
  79.     Application.StatusBar = False
  80.     Resume    '重返查詢
  81. End Sub
複製代碼
以前可以下載到...現在下不到,請求高手解惑

回復 2# chen_cook


    謝謝!原來問題已有人先發現

    靜待高手解決

TOP

回復 4# lalalada

這樣就無法一次自動下載了!是嗎

TOP

回復 10# lalalada


    請問要加到哪裡?這段程式....會比較快嗎?

TOP

GBKEE大大感謝你分享上市資料抓取內碼....感恩!
上櫃可否也請你分享抓取方式
謝謝!

TOP

好厲害!厲害......
成功了
等待版主分享完整下載上櫃資料內碼
感恩

TOP

        靜思自在 : 盡多少本份,就得多少本事。
返回列表 上一主題