Dim Xmlhttp As Object, Jsondata As Object, Url As String, Urla As String, DecodeJson, Databuy, Datasell, day As String, datalength As Integer, buy_length As Integer, sell_length As Integer, d, temp On Error Resume Next Set Jsondata = CreateObject("HtmlFile") Jsondata.write ”<script>document.JsonParse=function (s) {return eval(’(’ + s + ’)’);}</script>” 'Jsondata.write 這行符號是全形字,複製後,請改成半形,或直接看附加檔案
If Weekday(Date) = 1 Then d = 2 If Weekday(Date) = 7 Or Time < TimeValue("16:00") Then d = 1 day = Format(InputBox("請輸入查詢日期(8碼數字)", , Format(Date - d, "yyyymmdd")), "####-##-##") If day = "" Then Exit Sub
Dim url, HTMLsourcecode, GetXml Set HTMLsourcecode = CreateObject("htmlfile") Set GetXml = CreateObject("msxml2.xmlhttp") url = "https://goodinfo.tw/StockInfo/StockCashFlow.asp?STOCK_ID=2317&RPT_CAT=M_QUAR"
With GetXml .Open "GET", url, False .setRequestHeader "Content-Type", "application/x-www-form-urlencoded" .setRequestHeader "Cache-Control", "no-cache" .setRequestHeader "Pragma", "no-cache" .setRequestHeader "If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT" .setRequestHeader "User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)" .send Do Until .readyState = 4: DoEvents: Loop HTMLsourcecode.body.innerhtml = .responsetext
Set Table = HTMLsourcecode.all.tags("table")(17).Rows For i = 2 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 HTMLsourcecode = Nothing Set GetXml = Nothing End Sub
Sub postmethod()
Dim HTMLsourcecode, Clipboard As Object Set HTMLsourcecode = CreateObject("htmlfile") Set Clipboard = CreateObject("new:{1C3B4210-F441-11CE-B9EA-00AA006B1A69}")
With Clipboard .SetText HTMLsourcecode.body.innerhtml .PutInClipboard End With With Sheets("Raw") .Select .Cells.Clear .Cells(1, 1).Select .PasteSpecial NoHTMLFormatting:=True .Columns.ColumnWidth = 10 .Columns(1).ColumnWidth = 20 .Columns(1).WrapText = True .Cells(1, 1).Select End With End With 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 = "utf-8" convertraw = .ReadText .Close End With