activer wrote:
本國上市證券國際證券辨識號碼一覽表(https://isin.twse.com.tw/isin/C_public.jsp?strMode=2),以範例程式無法下載,瀏覽器F12無法看到內容,能否指點一下修正方式?
f12 不是看不到,是因為這個網頁容量超大,單純文字表格就用10M
有些瀏覽器會直接顯示out of memory
有些要等超久才出來,快14萬行的原始碼


vba出錯是因為要轉編碼

Sub get_twsw_isin()
Dim URL As String, HTML As Object, GetXml As Object
Set HTML = CreateObject("htmlfile")
Set GetXml = CreateObject("msxml2.xmlhttp")
URL = "https://isin.twse.com.tw/isin/C_public.jsp?strMode=2"
With GetXml
.Open "GET", URL, False
.setRequestHeader "Cache-Control", "no-cache"
.setRequestHeader "Pragma", "no-cache"
.setRequestHeader "If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT"
.send
HTML.body.innerhtml = ConvertRaw(.ResponseBody)
Set Table = HTML.all.tags("table")(1).Rows
For i = 0 To Table.Length - 1
For j = 0 To Table(i).Cells.Length - 1
ActiveSheet.Cells(i + 1, j + 1) = Table(i).Cells(j).innertext
Next j
Next i
End With
Set HTML = Nothing
Set GetXml = Nothing
End Sub
Function ConvertRaw(rawdata)
Dim rawstr
Set rawstr = CreateObject("adodb.stream")
With rawstr
.Type = 1
.Mode = 3
.Open
.Write rawdata
.Position = 0
.Type = 2
.Charset = "big5"
ConvertRaw = .ReadText
.Close
End With
Set rawstr = Nothing
End Function