Home > Enterprise >  Parse a value from a html response
Parse a value from a html response

Time:08-18

I'm trying to grab a CSRF nonce and JSESSIONID from a tomcat server to automate a war file upload tool I'm building.

I get the response of the page containing the nonce and JSESSIONID, but it's amongst a ton of HTML code.

My question is: What is the most efficient/easiest way to extract this information from the response?

An example of a bit of the response containing the nonce is as follows:

<td ><a href="/manager/status;jsessionid=34204725C78AB44888F4C107BFF0D782?org.apache.catalina.filters.CSRF_NONCE=FB57DCEE21FCFEA380C05F34759E666D">Server Status</a></td>

CodePudding user response:

Use some HTML parser like https://jsoup.org/ to parse the HTML, then navigate on the obtained structure to find the snippets of interest.

In case of JSoup follow this nice example: https://jsoup.org/cookbook/extracting-data/dom-navigation

  • Related