Extracting a text from a webpage

How do I find a text in a webpage, and if it finds that specific texts in that page, it should go ahead with further conditions.

What browser are you using? And can your provide a sample case? A site and the text you may be looking for there?

@aravindhstanley, in addition to what @cfriend asked for, please provide your entire use case/workflow. If we have the complete picture up front, it will greatly help us help you get a better solution faster.

1 Like

Ok here is the case.

We use an internal site for the ticketing system. But here is the sample requirment.

Each ticket (a webpage) will be in the below format.

Status Code : #somenumber
Error description: -------
Customer Name: --------
Priority: -------

Here is my need.
If the Status Code: 196, then the macro should proceed. I’m using if else command for this. Dont know how to specify the condition in the IF.

That's good, but we need to see the actual HTML code for the web page where this occurs.

  1. In Chrome, right-click on "Status Code" and select, "Inspect".
  2. Then in the Chrome Dev Tools (which will popup), select the <div> tag that is the parent tag for this, right-click on it, and select "Copy Outer HTML".
  3. Paste that HTML code here using the code block markdown with html as the language:



sample: Sample
Client Name: sample client
Policy Name: Sample
Schema Name: Sample
Job Id: Sample
Start Date:
End Date:
Status Code: 196


image @JMichaelTX

I need the HTML code as text (not an image) that covers all of the above, plus one node level above that.

To enter the HTML as text in a Markdown Code Block, see:

How to Put Script in a Forum Code Block

Just insert your script/code/text between the lines with the triple backquotes:

See Markdown for Code Blocks

To get syntax highlighting, then use the keyword in lower case for that language, like:

Here is a macro that will paste the script on the clipboard into the forum in the proper format:

MACRO: KM Forum -- Paste Script Block

You can probably just use the whole page text document.body.innerText and then test that for contains “Status Code: 196”.

Use the actions:Execute a JavaScript in Browser action to run the document.body.innerText JavaScript, and save it in to a variable, and then search that variable for your status code.

1 Like

@aravindhstanley, that is always a great fall-back approach when the direct approach doesn't work, or is too difficult to figure out. However, it comes with two caveats:

  1. May not give you a unique solution.
  2. May take longer to search through the entire text of a web page.

In the end, it comes down to what works best for you that provides a reliable solution.

I do use it sometimes. For example, I have a script to get the Publication Date of a web page. First I look for common HTML elements that usually contain this date, but if I don't find any then I do a full text search looking for the first date I find. It often works, but sometimes I get a date other than the publication date.