Jump to content

Recommended Posts

Posted

Hello friends, I need help to get data from URL . 

The URL is here:

https://www.twse.com.tw/rwd/trading/fund/MI_QFIIS?date=20230505&selectType=24&response=json

 

I want to get the value from "data", is it possible?

How should I modify my code? Can anyone help me...

#include<Array.au3>
#include<Date.au3>
#include<FileConstants.au3>
#include<wd_core_au3>
#include<wd_helper.au3>
#include<Json.au3>
#include<String.au3>
#include<File.au3>
#include<WinHttp.au3>
#include<WinHttpConstants.au3>
#include <Inet.au3>

$URL = "https://www.twse.com.tw/rwd/trading/fund/MI_QFIIS?date=20230505&selectType=24&response=json"
$data = _INetGetSource($URL)
$object = json_decode($data)

Local $i = 0
While 1
    $oData = json_get($object, '[' & $i & '].data')
    ConsoleWrite('$oData== ' & oData & @CRLF)
    $i += 1
WEnd

I got the output: 

$oData==
  • Solution
Posted

Try this --

#include "json.au3"
#include <Inet.au3>

$URL = "https://www.twse.com.tw/rwd/trading/fund/MI_QFIIS?date=20230505&selectType=24&response=json"
$data = _INetGetSource($URL)
$oJSON = json_decode($data)

Local $i = 0

While Not @error
    $oData = Json_Get($oJSON, '.data[' & $i & ']')
    If Not @error Then
        $sData = Json_Encode($oData)
        ConsoleWrite('Data #' & $i & @CRLF)
        Json_Dump($sData)
    EndIf
    $i += 1
WEnd

 

Posted (edited)

Here's another way:

#AutoIt3Wrapper_AU3Check_Parameters=-w 3 -w 4 -w 5 -w 6 -d

#include <Constants.au3>
#include <jq\jq.au3>
#include <Array.au3>

Const $JQ_EXE = "C:\Utils\jq\jq-win64.exe"

example()

Func example()
    Local $sJson   = "", _
          $sResult = ""

    Local $aResult[0][12]

    Local $hTimer = 0

    ;Get JSON result from the web
    $sJson = InetRead("https://www.twse.com.tw/rwd/trading/fund/MI_QFIIS?date=20230505&selectType=24&response=json")
    If @error Then Return MsgBox($MB_ICONERROR, "InetRead() Error", "@error = " & @error)
    $sJson = BinaryToString($sJson, $SB_UTF8)

    ;Start timer
    $hTimer = TimerInit()

    ;Initialize jq
    _jqInit($JQ_EXE)
    If @error Then Return MsgBox($MB_ICONERROR, "_jqInit() Error", "@error = " & @error)

    ;Get "data" from JSON.  Return as a tab-separated-value list.
    $sResult = _jqExec($sJson, ".data[]|@tsv")
    If @error Then Return MsgBox($MB_ICONERROR, "_jqExec() Error", "@error = " & @error)

    ;Add data to an array
    _ArrayAdd($aResult, $sResult, 0, @TAB)
    If @error Then Return MsgBox($MB_ICONERROR, "_ArrayAdd() Error", "@error = " & @error)

    ConsoleWrite(StringFormat("JSON processing time: %.3f seconds.",  TimerDiff($hTimer)/1000) & @CRLF)

    ;Display array
    _ArrayDisplay($aResult)
EndFunc

Console output:

JSON processing time: 0.059 seconds.

Resulting array:

image.png.c5a18e42095dd51e577cd4e94bd686e4.png

 

Result in jqPlayground:

image.png.887443bb6ae205bf97f190c5172ae208.png

Edited by TheXman
Posted (edited)

Maybe NTP ?

 

 

Edited by mLipok

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted

@Danp2 Thanks for your reply😄

When I tried to modify from While Not @error to While 1, and print the output. It couldn't run at

Json_Dump($sData) 

The error message was "Unknown function name". Is the error meaning  I didn't add another library?

Posted

I updated the JSON  UDF that you gave me and it could work! But when I add  

ConsoleWrite(“$output: ”& _Dump($sData ) & @CRLF)

want to print the data, the output was

$output: 0

I don’t know why it print “0”?

Posted

_Dump() ?

why not 
Json_Dump()

 

?

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted

Oops…

I missed to paste (my mistake )

Here is my code. 

ConsoleWrite(“$output: ”&Json _Dump($sData ) & @CRLF)

$output: 0

  • Developers
Posted
  On 5/8/2023 at 7:53 AM, Flora said:

Oops…

I missed to paste (my mistake )

Expand  

The code is again not valid as there's a space after json!
Please post your exact code into a codeblock ( post code <>) here so we can see what you are doing. ;) 

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...