- 帖子
- 5923
- 主題
- 13
- 精華
- 1
- 積分
- 5986
- 點名
- 0
- 作業系統
- win10
- 軟體版本
- Office 2010
- 閱讀權限
- 150
- 性別
- 男
- 來自
- 台灣基隆
- 註冊時間
- 2010-5-1
- 最後登錄
- 2022-1-23
        
|
7#
發表於 2018-11-14 16:07
| 只看該作者
回復 6# PKKO
試試看- Option Explicit
- Sub Ex_中文亂碼_GET()
- Dim strText As String
- Dim I As Integer, j As Integer, xTable As Object
- With CreateObject("msxml2.xmlhttp")
- .Open "GET", "http://mops.twse.com.tw/nas/t21/sii/t21sc03_107_4_0.html", False
- .setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
- .send
- strText = BinToStr(.responseBody, "BIG5") '要注意網頁編碼
- End With
- With CreateObject("htmlfile")
- .Write strText
- Set xTable = .all.tags("table")(2)
- With ActiveSheet
- .Cells.Clear
- For I = 0 To xTable.Rows.Length - 1
- For j = 0 To xTable.Rows(I).Cells.Length - 1
- .Cells(I + 1, j + 1) = xTable.Rows(I).Cells(j).innertext
- Next
- Next
- End With
- End With
- End Sub
- Function BinToStr(arrBin, strChrs)
- With CreateObject("ADODB.Stream")
- .Type = 2
- .Open
- .Writetext arrBin
- .Position = 0
- .Charset = strChrs
- BinToStr = .ReadText
- .Close
- End With
- End Function
複製代碼 |
|