Jump to content

Splitting a Array in different variables


Recommended Posts

Hi there I am new to autoIT and am trying to create a script which filters HTML sourcecode on a messages and returns a pop up with the latest one.

Here is a example of the sourcecode:

"MessageID":19652,"Timestamp":"2019-12-24T07:46:51.713","Tag":"","Text":"Text here","Type":"Chat","Votes":1,"Enabled":true,"User":{"Name":"Kaasplake","Division":"X"},"Division":"X"},{

I filter the sourcecode with :

$Source = BinaryToString(InetRead('https://ccsd.intern.rabobank.nl/Shoutbox/', 1))

;Select the chunks from the website source code
$FirstChunks = _StringBetween($Source, '{"MessageID":', '"},' ) ;Takes the log from the source code

For $a In $FirstChunks
 ConsoleWrite($a & @CRLF)
Next

Which returns a array filled with every chunk of the source code. But now I want to filter these chunks further into lets say: $name , $message, $date but I am not sure how to do this in AutoIT could you guys push me into the right direction.

Thanks a lot from a starting autoIT user.

- Kaasplakje

 

 

 

Link to post
Share on other sites
  • Developers

@Kaasplakje,   

That data looks a lot like a part of a JSON encoded dataset. Maybe it is easier to simply use one of the json UDF's available in the form to read the data.
We would require a proper set of outputdata to assist though.

Jos

 

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 post
Share on other sites

One other solution is to use SRE to extract the 3 fields into an array like this :

#include <Array.au3>

Const $sTxt = '"MessageID":19652,"Timestamp":"2019-12-24T07:46:51.713","Tag":"","Text":"Text here","Type":"Chat","Votes":1,"Enabled":true,"User":{"Name":"Kaasplake","Division":"X"},"Division":"X"},{'
Local $aArray = StringRegExp ($sTxt, '"Timestamp":"(.+?)".+"Text":"(.+?)".+"Name":"(.+?)"', $STR_REGEXPARRAYMATCH)
_ArrayDisplay ($aArray)

I suppose message = Text ?

Btw : you could do all in SRE without using _StringBetween...

Edited by Nine
Link to post
Share on other sites


Hi Jos,

Thanks for the reply. I only have access to the source code via > chrome inspect and am not sure where I can find the proper JSON encoded dataset to show this to you. I looked into the .js file and found this but as I said I'm not sure if this is what you need as proper set to assist me.

------- This is displayed in the .js file ------

var newMessage = messageTemplate(id, name, division, time, tag, text, type, enabled);

var messageTemplate = function (id, name, division, time, tag, text, type, enabled) {

------- This is displayed in the view-source: ------

//Load all messages, teams, tags and incidents
  $(document).ready(function () {
   
  //Show the appropriate messages upon loading
  UserPreferences = JSON.parse('{"Team":true,"Masterincidenten":true,"Sos":true,"Meldingen":true,"Chat":true}');
  addMessages([{"MessageID":19652,"Timestamp":"2019-12-24T07:46:51.713","Tag":"","Text":"Here is the supposed text","Type":"Chat","Votes":1,"Enabled":true,"User":{"Name":"Kaasplakje","Division":"X"},"Division":"X"},
Link to post
Share on other sites

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...