Find text in source page with JavaScript

Hello all,
I wonder how can I find a specific text in the source of a web page.
I know I can find DOM elements with JavaScript, with statements like that
“color =”
but I need to find text that is not part of the DOM Objects.

I know JavaScript has some functions to search in the page, but I need to search in the source page, not in the rendered html page.

To be more specific, when I check news on a specific website like this:
I need to make a script (a bookmarklet or a greasemonkey script) to extract the date, and therefore I have to search for the text “<span class=“date”>”

In other words: how can I make a script or a Firefox addon to “grep” for a certain text on a web site?

I am using Firefox browser, so for me it’s enough a solution that only works in that browser.


I found the solution, in case anyone else needs something similar:

var x = document.body.innerHTML;
x = x.match(/*/)[0];
x = x.replace(/…/, “”);
x = x.replace(/…span/, “”);

So long as you’re using a modern browser you could use document.getElementsByClassName(); to get the date element. If you would need to narrow it down to only a specific area (to save having to look through a whole document) you could use something like

var el = document.getElementById("main-content");
var articleDate = el.getElementsByClassName("date")[0].innerHTML; // [0] is there to return the first element only.