- 帖子
- 5923
- 主題
- 13
- 精華
- 1
- 積分
- 5986
- 點名
- 0
- 作業系統
- win10
- 軟體版本
- Office 2010
- 閱讀權限
- 150
- 性別
- 男
- 來自
- 台灣基隆
- 註冊時間
- 2010-5-1
- 最後登錄
- 2022-1-23
        
|
20#
發表於 2022-1-12 09:58
| 只看該作者
本帖最後由 GBKEE 於 2022-1-12 10:00 編輯
回復 18# wufonna
多寫幾行試試試試看- Private Sub GetIncome() '取損益表(年表)網頁
- Dim Url, HTMLsourcecode, GetXml, TableG As Object, i As Integer, j As Integer, a As Integer
- Set HTMLsourcecode = CreateObject("htmlfile")
- Set GetXml = CreateObject("msxml2.xmlhttp")
- Url = "http://kgieworld.moneydj.com/z/zc/zcq/zcqa/zcqa_2330.djhtm"
- With GetXml
- .Open "GET", Url, False
- .send
- HTMLsourcecode.write .Responsetext
- Do ' 程式運行速度快用迴圈,確保TableG物件下載完整
- Set TableG = HTMLsourcecode.all.tags("div")
- DoEvents
- '** "JScriptTypeInfo" 可在 區域變數視窗 查看
- '** 或是 Debug.Print TypeName(TableG) 得知
- Loop Until TypeName(TableG) = "JScriptTypeInfo"
- '*****得知 classname="table-row" 的位置
- For a = 0 To TableG.Length - 1
- 'Debug.Print a, TableG(a).classname
- If TableG(a).classname = "table-row" Then Exit For '讀取資料起始列數
- Next
- '***************************************
- With ActiveSheet
- .Cells.Clear
- For i = a To TableG.Length - 1
- For j = 0 To TableG(i).all.tags("span").Length - 1
- .Cells(i - (a - 1), j + 1) = TableG(i).all.tags("span")(j).innertext
- '****** i - ( a-1) >>修正從第一列開始下載資料
- Next j
- Next i
- End With
- '***網頁的編碼**********************************
- '<div class="table-row"> 為所要的資料 的網頁元素
- '<span class="t2 table-cell">期別</span>
- '<span class="t2 table-cell">2020</span>
- '<span class="t2 table-cell">2019</span>
- '<span class="t2 table-cell">2018</span>
- '<span class="t2 table-cell">2017</span>
- '<span class="t2 table-cell">2016</span>
- '<span class="t2 table-cell">2015</span>
- '<span class="t2 table-cell">2014</span>
- '<span class="t2 table-cell">2013</span>
- '</div>************************************
- End With
- Set HTMLsourcecode = Nothing '釋放記憶體
- Set GetXml = Nothing
- End Sub '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
複製代碼 |
|