返回列表 上一主題 發帖

[發問] 網路CSV下載問題

回復 1# spermbank

建議從解析原始資料網址著手,若該網頁版面設計變更,程式碼不需修改,比較不容易受到影響。程式碼用錄的(WEB查詢-Querytable)就可以取得.....就不寫了....

實施IFRS之前[101年第4季(含)以前]

個別損益表
http://mops.twse.com.tw/mops/web/ajax_t51sb08?encodeURIComponent=1&step=1&firstin=1&off=1&TYPEK=sii&year=101&season=04

個別資產負債表
http://mops.twse.com.tw/mops/web/ajax_t51sb07?encodeURIComponent=1&step=1&firstin=1&off=1&TYPEK=sii&year=101&season=04

合併損益表
http://mops.twse.com.tw/mops/web/ajax_t51sb13?encodeURIComponent=1&step=1&firstin=1&off=1&TYPEK=sii&year=101&season=04

合併資產負債表
http://mops.twse.com.tw/mops/web/ajax_t51sb12?encodeURIComponent=1&step=1&firstin=1&off=1&TYPEK=sii&year=101&season=04

上市 TYPEK=sii
上櫃 TYPEK=otc
year = 民國年, 例 102
season = 季度, 例 01, 02, 03, 04
diabo

TOP

回復 5# HSIEN6001

同上一篇回覆,簡化問題從源頭開始....

http://mops.twse.com.tw/mops/web/ajax_t56sb21?encodeURIComponent=1&run=Y&step=1&TYPEK=sii&year=102&smonth=01&emonth=03&sstep=1&firstin=true
diabo

TOP

回復 1# spermbank
  1. Sub 抓財報(財報別, 市場別, 年, 季)
  2.    
  3.     Select Case 財報別
  4.         Case "損益":     程式 = "ajax_t51sb08"
  5.         Case "資產":     程式 = "ajax_t51sb07"
  6.         Case "合併損益": 程式 = "ajax_t51sb13"
  7.         Case "合併資產": 程式 = "ajax_t51sb12"
  8.     End Select
  9.    
  10.     Select Case 市場別
  11.         Case "上市": 市場 = "sii"
  12.         Case "上櫃": 市場 = "otc"
  13.         Case "興櫃": 市場 = "rotc"
  14.         Case "公開": 市場 = "pub"
  15.     End Select
  16.    
  17.    '原始網址 http://mops.twse.com.tw/mops/web/ajax_t51sb07?encodeURIComponent=1&step=1&firstin=1&off=1&TYPEK=sii&year=101&season=04
  18.     theURL = "http://mops.twse.com.tw/mops/web/" & 程式 & "?encodeURIComponent=1&step=1&firstin=1&off=1&TYPEK=" & 市場 & "&year=" & 年 & "&season=" & 季
  19.    
  20.     With ActiveSheet.QueryTables.Add(Connection:="URL;" & theURL, Destination:=Range("A1"))
  21.         .Name = "抓財報"
  22.         .BackgroundQuery = True
  23.         .RefreshStyle = xlOverwriteCells
  24.         .RefreshPeriod = 0
  25.         .WebSelectionType = xlEntirePage
  26.         .WebFormatting = xlWebFormattingNone
  27.         .WebDisableDateRecognition = False
  28.         .WebDisableRedirections = False
  29.         .Refresh BackgroundQuery:=False
  30.         .Delete
  31.     End With
  32.    
  33. End Sub
複製代碼
1. 以上程式碼僅抓資料,並未處理金融保險證券...類股會計科目不同的問題
2. 使用範例  call 抓財報( "損益","上櫃",101,"04")
diabo

TOP

回復 11# HSIEN6001


    檢視IE的編碼,是否選擇「自動編碼」......
diabo

TOP

回復 13# HSIEN6001


1.  EXCEL的WEB查詢,也是透過IE,因此IE的設定會影響到下載的結果。
2.  IE     檢視→編碼→自動選取

抓財報彙總表.rar (327.74 KB)
diabo

TOP

        靜思自在 : 心中常存善解、包容、感思、知足、惜福。
返回列表 上一主題