返回列表 上一主題 發帖

[發問] 如何找出網站原始檔網址

[發問] 如何找出網站原始檔網址

我想用web查詢,下載公開觀測站的資料,到excel,要如何找出原始檔網址

我想找的網址如下:董監事持股餘額明細資料內的歷史資料
http://mops.twse.com.tw/mops/web/stapap1?

還請逹人大大幫忙,感恩謝謝

回復 1# blue2263
試試看
  1. Option Explicit
  2. Sub 公開資訊網頁()
  3.     Dim A As Object, E As Object
  4.     With CreateObject("InternetExplorer.Application")
  5.         .Visible = True
  6.         ' .Navigate "http://mops.twse.com.tw/mops/web/t164sb04"     '網址:綜合損益表
  7.         .Navigate "http://mops.twse.com.tw/mops/web/stapap1"        '網址:董監事持股餘額明細資
  8.         Do While .ReadyState <> 4 Or .Busy: DoEvents: Loop
  9.             .document.getElementById("isnew").Value = "false"       '選擇: 歷史資料
  10.             '註解上一行程式碼為 -> 選擇: 最新資料,不會執行 If 內程式碼
  11.            
  12.             If .document.getElementById("isnew").Value = "false" Then
  13.              .document.getElementById("isnew").FireEvent ("onchange")
  14.                 .document.getElementById("year").Value = "102"       '年度
  15.                 '.document.getElementById("season").Value = "01"    '綜合損益表:第1季(季別)
  16.                 .document.getElementById("month").Value = "08"      '董監事持股餘額明細資料:月份
  17.             End If
  18.             '********************************************************************
  19.            For Each A In .document.getelementSbyTAGNAME("INPUT")
  20.                 If A.Name = "co_id" Then A.Value = "2303"            '股票代號
  21.                 If A.Value = " 搜尋 " Then A.Click                     '按下 搜尋
  22.             Next
  23.             Do While .ReadyState <> 4 Or .Busy: DoEvents: Loop
  24.             For Each E In .document.ALL.TAGS("div")
  25.                 If E.ID = "table01" Then
  26.                     .document.body.innerHTML = E.outerHTML
  27.                     .ExecWB 17, 2       '  Select All
  28.                     .ExecWB 12, 2       '  Copy selection
  29.                     With ActiveSheet
  30.                         .Cells.Clear
  31.                         .Cells(1).Select
  32.                         .PasteSpecial Format:="HTML"
  33.                     End With
  34.                 End If
  35.             Next
  36.         .Quit                          '關閉 IE
  37.     End With
  38. End Sub
複製代碼
感恩的心......(在麻辣家族討論區.用心學習會有進步的)
但資源無限,後援有限,  一天1元的贊助,人人有能力.

TOP

回復 1# blue2263
  1. http://mops.twse.com.tw/mops/web/ajax_stapap1?encodeURIComponent=1&step=1&firstin=1&off=1&queryName=co_id&TYPEK=all&isnew=false&co_id=1101&year=102&month=11
複製代碼
co_id=1101&year=102&month=11  

TOP

感謝G大回復,G大真是神人,原來還有這種直接打開IE下載資料的作法
請教G大,比如A1儲存格輸入股票代碼,A2年度,A3月份,我要用儲存格來更改,我要下載的資料
,巨集要如何更改,麻煩你了感恩
另外請教G大,有沒這方面推薦的書籍或教程,VBA我還是個超級新手

TOP

謝謝stillfish00 大回復
請教原始檔網址是如何找出來的,可以教我嗎,謝謝

TOP

回復 4# blue2263

   
A1儲存格輸入股票代碼,A2年度,A3月份

程式碼中有註解 股票代碼 ,年度,月份
將那些=字串 取代為 A1,A2,A3
感恩的心......(在麻辣家族討論區.用心學習會有進步的)
但資源無限,後援有限,  一天1元的贊助,人人有能力.

TOP

G大你好
我將 If A.Name = "co_id" Then A.Value = "2330"        '股票代號
改為 If A.Name = "co_id" Then A.Value = A1        '股票代號
出現編譯錯誤,是我那邊改錯了,請幫我看一下謝謝

TOP

回復 7# blue2263

A1是工作表上的位置, VBA 語法 Range("A1")
  1. If A.Name = "co_id" Then A.Value =Range("A1")        '股票代號
複製代碼
感恩的心......(在麻辣家族討論區.用心學習會有進步的)
但資源無限,後援有限,  一天1元的贊助,人人有能力.

TOP

謝謝g大解答

TOP

可否請G大, 再幫我下列網址,資料用VBA方式下載,程式碼要如何寫
http://www.tdcc.com.tw/smWeb/QryStock.jsp
感恩謝謝!

TOP

        靜思自在 : 脾氣嘴巴不好,心地再好也不能算是好人。
返回列表 上一主題