Flora Posted May 5, 2023 Share Posted May 5, 2023 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== Link to comment Share on other sites More sharing options...
Solution Danp2 Posted May 5, 2023 Solution Share Posted May 5, 2023 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 Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
TheXman Posted May 5, 2023 Share Posted May 5, 2023 (edited) Here's another way: expandcollapse popup#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: Result in jqPlayground: Edited May 5, 2023 by TheXman CryptoNG UDF: Cryptography API: Next Gen jq UDF: Powerful and Flexible JSON Processor | jqPlayground: An Interactive JSON Processor Xml2Json UDF: Transform XML to JSON | HttpApi UDF: HTTP Server API | Roku Remote: Example Script About Me How To Ask Good Questions On Technical And Scientific Forums (Detailed) | How to Ask Good Technical Questions (Brief) "Any fool can know. The point is to understand." -Albert Einstein "If you think you're a big fish, it's probably because you only swim in small ponds." ~TheXman Link to comment Share on other sites More sharing options...
mLipok Posted May 5, 2023 Share Posted May 5, 2023 (edited) Maybe NTP ? Edited May 5, 2023 by mLipok TheXman, Danp2 and funkey 2 1 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 Code * for other useful stuff click the following button: Spoiler Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST API * ErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 * My contribution to others projects or UDF based on others projects: * _sql.au3 UDF * POP3.au3 UDF * RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF * SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane * Useful links: * Forum Rules * Forum etiquette * Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * Wiki: * Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX IE Related: * How to use IE.au3 UDF with AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskScheduler * IE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related: * How to get reference to PDF object embeded in IE * IE on Windows 11 * I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions * EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *I also encourage you to check awesome @trancexx code: * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuff * OnHungApp handler * Avoid "AutoIt Error" message box in unknown errors * HTML editor * winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/ "Homo sum; humani nil a me alienum puto" - Publius Terentius Afer"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming" , be and \\//_. Anticipating Errors : "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty." Signature last update: 2023-04-24 Link to comment Share on other sites More sharing options...
Flora Posted May 6, 2023 Author Share Posted May 6, 2023 @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? Link to comment Share on other sites More sharing options...
Danp2 Posted May 6, 2023 Share Posted May 6, 2023 Which JSON UDF are you using? I'm using the one from here. The code I posted should run without modification. Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
Flora Posted May 8, 2023 Author Share Posted May 8, 2023 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”? Link to comment Share on other sites More sharing options...
mLipok Posted May 8, 2023 Share Posted May 8, 2023 _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 Code * for other useful stuff click the following button: Spoiler Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST API * ErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 * My contribution to others projects or UDF based on others projects: * _sql.au3 UDF * POP3.au3 UDF * RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF * SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane * Useful links: * Forum Rules * Forum etiquette * Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * Wiki: * Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX IE Related: * How to use IE.au3 UDF with AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskScheduler * IE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related: * How to get reference to PDF object embeded in IE * IE on Windows 11 * I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions * EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *I also encourage you to check awesome @trancexx code: * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuff * OnHungApp handler * Avoid "AutoIt Error" message box in unknown errors * HTML editor * winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/ "Homo sum; humani nil a me alienum puto" - Publius Terentius Afer"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming" , be and \\//_. Anticipating Errors : "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty." Signature last update: 2023-04-24 Link to comment Share on other sites More sharing options...
Flora Posted May 8, 2023 Author Share Posted May 8, 2023 Oops… I missed to paste (my mistake ) Here is my code. ConsoleWrite(“$output: ”&Json _Dump($sData ) & @CRLF) $output: 0 Link to comment Share on other sites More sharing options...
Developers Jos Posted May 8, 2023 Developers Share Posted May 8, 2023 26 minutes ago, Flora said: Oops… I missed to paste (my mistake ) 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. Link to comment Share on other sites More sharing options...
Flora Posted May 15, 2023 Author Share Posted May 15, 2023 I tried two method from @Danp2 and @TheXman finally it could works. Thanks your help😀 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now