[Help] Searching pages - Printable Version
-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Messenger Plus! for Live Messenger (/forumdisplay.php?fid=4)
+---- Forum: Scripting (/forumdisplay.php?fid=39)
+----- Thread: [Help] Searching pages (/showthread.php?tid=64786)
[Help] Searching pages by Paril on 08-11-2006 at 12:57 PM
Hello.
I'm sure this has been asked before, but I did a search and didn't find anything close to this..
Is it possible to make a script search a website, and return the results into a var (used for checking for certain text)?
An example would be searching the main page of my site, returning the results of all the text found on the main page, finding the first instance of Update, then seeing what 3 chars after it are.
-Paril
RE: [Help] Searching pages by RaceProUK on 08-11-2006 at 03:35 PM
I imagine it's possible, since JScript can deal with XML stuff, but that would mean the webpage has to be valid XHTML.
Other than that, you could use some regular expressions to fetch only what you need from the page.
RE: [Help] Searching pages by Paril on 08-11-2006 at 03:37 PM
Could ya help me on that?
Maybe on MSN we can discuss this?
RE: [Help] Searching pages by AberNStein on 08-11-2006 at 04:34 PM
i've got a script doing pretty much that. i had a thread about it a while ago.
the checkdupe(datum) function checks whether the given input is in the logfile (returns true or false), and the logging(datum) saves the given input to the logfile
getdata() reads the given website, and then calls parseTt(htmls).
in my script, parseIt iterates through all the links in the page, then for each one with "[release]" in the link's innerHTML that isn't already in the logfile, it pops up a toast. then it adds it to the logfile. pretty straightforward really.
oh and the script might give you a runtime error. ignore it.
right now it just goes when i start up messenger but it wouldn't be hard to make it go every 10 mins or whatever. just call getData();
code: function OnEvent_Initialize(MessengerStart) {
}
var TheFile = MsgPlus.ScriptFilesPath + "\\log.txt";
var fso = new ActiveXObject("Scripting.FileSystemObject");
var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
getData();
function checkDupe(datum) {
if(fso.FileExists(TheFile)) {
var a = fso.OpenTextFile(TheFile, 1);
var text = a.ReadAll();
text = text.split('\r\n');
for(var i = 0;i<text.length;i++)
if(text[i] == datum) {
a.Close();
return true;
}
a.Close();
return false;
}
}
function logging(datum) {
if(fso.FileExists(TheFile)) {
if(checkDupe(datum))
return;
a = fso.OpenTextFile(TheFile, 8);
} else
var a = fso.OpenTextFile(TheFile,2,true);
a.WriteLine(datum);
a.Close();
}
function getData() {
xmlhttp.open("GET", "http://shoutbox.menthix.net/forumdisplay.php?fid=39", true);
xmlhttp.onreadystatechange = stateChanged;
xmlhttp.send(null);
}
function stateChanged() {
if (xmlhttp.readyState==4)
if (xmlhttp.status==200)
parseIt(xmlhttp.responseText);
}
function parseIt(htmls)
{
var foo = "";
var oDoc = new ActiveXObject("htmlfile");
oDoc.open();
oDoc.write(htmls);
oDoc.close();
var links = oDoc.getElementsByTagName("a");
for (var i=0; i<links.length; i++) {
foo = links[i].innerHTML.toLowerCase()
if (foo.indexOf("[release]") > -1 && !checkDupe(links[i].innerHTML)) {
MsgPlus.DisplayToast("MsgHelp.net [Release]",links[i].innerHTML,'','OpenSite',links[i].HREF);
logging(links[i].innerHTML);
}
}
}
function OpenSite(url) {
new ActiveXObject('WScript.Shell').run('http://shoutbox.menthix.net/' + url);
}
function OnEvent_Uninitialize(MessengerExit) {
}
edit: for some reason OpenSite(url) isn't working properly. i'd much appreciate it if someone could go over my code and improve it. if not, i'll fix it when i get back (i'm going away for two weeks).
RE: [Help] Searching pages by Paril on 08-11-2006 at 05:22 PM
..It'll be called when you type a command, I can't see why I would want it to be automatic, it would be annoying to everyone that I have a window open with.
It should just return all of the text on the page into a var or char, then I'll be checking that var for a certain string, then returning an int.
RE: [Help] Searching pages by Paril on 08-11-2006 at 08:19 PM
No one has a solution?
RE: [Help] Searching pages by AberNStein on 08-11-2006 at 09:21 PM
well you could modify my code
that's why i posted it.
code: var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
var YourSite = "http://www.example.com";
var YourData = "";
function getData() {
xmlhttp.open("GET", YourSite, true);
xmlhttp.onreadystatechange = stateChanged;
xmlhttp.send(null);
}
function stateChanged() {
if (xmlhttp.readyState==4)
if (xmlhttp.status==200)
YourData = xmlhttp.responseText;
}
that's just the bit that grabs the page and puts it into a variable.
you sound like you can parse it yourself.
RE: [Help] Searching pages by J-Thread on 08-11-2006 at 09:23 PM
Wouldn't:
code: var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
function getIt(url) {
xmlhttp.open("GET", url, true);
xmlhttp.onreadystatechange = stateChanged;
xmlhttp.send(null);
}
function stateChanged() {
if (xmlhttp.readyState==4)
if (xmlhttp.status==200)
var thevar = xmlhttp.responseText;
// Do here what you like with the var
}
do the trick?
RE: [Help] Searching pages by AberNStein on 08-11-2006 at 09:27 PM
lol i just edited my post to pretty much exactly that
edit: actually can variables that are declared within functions be used elsewhere? i'm not quite sure.
RE: [Help] Searching pages by J-Thread on 08-11-2006 at 09:38 PM
Globally variables can...
You can do:
code: var bla;
function a() {
// Do something
bla = "hello";
b();
}
function b() {
alert(bla);
}
but not:
code: function a() {
// Do something
var bla = "hello";
b();
}
function b() {
alert(bla);
}
RE: [Help] Searching pages by Paril on 08-12-2006 at 10:38 AM
Thanks, I'll try it!
|