Handling a Web Response (search for a specific value)


#1

Hello.
I’m currently working on a piston that like make a web request.
I want to be able to get the response, and then read the 1st (td) from 2nd (tr) element from a table and to store it on a variable.
Before I was using python with bs4 library but I wish to be able to do it directly on webCoRe
Is this possible?
Is a regex do the job?

Thanks


#2

HTML is parse-able in webCoRE, but a bit of a pain, and easily breakable if they change anything.
(IE: even if they change a totally unrelated paragraph)

Just dump $response into a string variable to see what webCoRE sees.
(Although, on giant web pages, you may have issues)


#3

If the return data is all just a table of data, you should be able to access either by using:

$response[row][col]

or, if you store into a string it will become one longe array and you will have to do something like:

arrayItem(row*ncols+col, stringData)

In both cases, [row, col] is the index of the item you want numbered from 0 and ncols is the number of columns in your table.


#4

No, it’s a light weight web site that is contains among others, one table.
I want to find a specific tr, td combination

EDIT
I was able to create a regex to catch the specific response.
is there an webcore expression to use this regex?

something like

{response}regex(‘/Longitude.*?:\d\d:\d{6}.\d\d(\d+.\d{2})/‘)

to return the match?


#5

Once you save the $response into a variable, you could use the indexOf function to search for a specific string. Combine this will trimming functions (left, right, mid) you should be able to pull the data.

Note: indexOf only pulls the first instance of the string

More details are available on the wiki https://wiki.webcore.co/Functions#indexOf

Ex.
response is Latitude 40.7484, Longitude -73.9857

  • indexOf(response,‘Longitude’) should return 18 (location of string); combine that with mid()
  • mid(response,indexOf(response,‘Longitude’)) would trim off everything prior to Longitude
  • If you only wanted the coordinates, add 10 to the indexOf (length on longitude_)
    mid(response,indexOf(response,‘Longitude’) + 10) should result in -73.9857

#6

If you need to work in reverse, there is also:
lastIndexOf()
which only pulls the last instance of the string


#7

Delete, I figured it out