VMware Cloud Community
dcouturier
Enthusiast
Enthusiast

Parse text/HTML

Hi

is there a way to parse a response (text/HTML) ?

Thanks for your help

0 Kudos
4 Replies
eoinbyrne
Expert
Expert

Hi

It depends what you want to do but yes, you could certainly write a fully functional parser for more or less any data

If you have a simple use-case such as verify that the value "status=SUCCESS" is found in a response you can do this

var responseText = "Operation completed : status=SUCCESS";

if(responseText.indexOf("status=SUCCESS") > -1)

{

     System.log("Operation succeeded!");

}

else

{

     System.log("Operation may have failed.... please check");

}

-HTH

0 Kudos
iiliev
VMware Employee
VMware Employee

Hi,

Could you describe the use case, eg. where this response comes from?

Usually, the systems have an API that returns responses in more structured format, like XML or JSON, and text/html might be an indication of some error/exception being thrown that is not meant to be parsed but instead displayed in the UI/browser.

Internally, vRO uses Rhino Javascript engine, which is a server-side framework and does not have direct support for DOM. You can try to parse the html as text, but this is very error prone, especially if the content of the html response is dynamic.

0 Kudos
dcouturier
Enthusiast
Enthusiast

I can't paste my HTML source. I don't why I get "access denied". The system I want to access does not have any API (for the moment). I made a script with Powershell that works (with invoke-webrequest).

I find a way to "parse" the HTML with a bunch of script found somewhere but it's not totally "clean". I have to split, clean my HTML source to try to have the good information. 

More I work on it and more I think it's not a good idea btw. Maybe I have to wait for the next version of my product to have API

0 Kudos
qc4vmware
Virtuoso
Virtuoso

I wouldn't wait on the api change if you are looking for some known values and have some expectation of what the possible outputs would be.   We interface with all sorts of systems and parse tons of outputs from know formats and also in house developed tools which just spit out plain text.  So long as you can key on something in the output you should be able to navigate things pretty reliably I would suspect.  If you can provide some samples we can help you with the parsing.

0 Kudos