What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Messenger Plus! for Live Messenger » Scripting » help me fix my script please

help me fix my script please
Author: Message:
AberNStein
Full Member
***


Posts: 132
Reputation: 2
Joined: Jul 2006
O.P. help me fix my script please
ok so i'm working on a new script that involves scraping a webpage. below is the scraping bit, along with a saveToFile function, so i can see what stuff returns.

the problem:
my xmlhttprequest is returning nothing.
the script:
code:
function OnEvent_Initialize(MessengerStart)
{
getData();
}

var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");

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)
    {
    saveToFile(xmlhttp.responseText);
    }
  else
    {
    saveToFile(xmlhttp.status);
    }
  }
}

function saveToFile(data1)
{
var fso, f1, thePath;
fso = new ActiveXObject("Scripting.FileSystemObject");
thePath = "C:\\file.txt";
f1 = fso.CreateTextFile(thePath, true);
f1.Write (data1);
f1.Close();
}


function OnEvent_Uninitialize(MessengerExit)
{
}


the script is kinda cut and pasted together from various sources, but it looks like it should work. it's returning a readystate of 4, but an http status of zero.

help me please.
[Image: gybouserbar6hc.gif]
07-14-2006 12:14 AM
Profile PM Find Quote Report
luisillo
Junior Member
**

Avatar
yo

Posts: 23
38 / Male / –
Joined: Jun 2006
RE: help me fix my script please
when you call your function, woudln't it be something about like that:
quote:
Originally posted by AberNStein
xmlhttp.onreadystatechange = stateChanged();
??

Otherwhise you are not calling the function, just telling it's name, and if I'm not wrong in the debug window it should say something like "Error inline xx not defined"
I hope this fixes your problem;)


Sorry, that is even worse, but your script DOES get the website's code, what's wrong whit your script? (sorry if this is a silly question)

This post was edited on 07-14-2006 at 12:35 AM by luisillo.
07-14-2006 12:27 AM
Profile PM Find Quote Report
AberNStein
Full Member
***


Posts: 132
Reputation: 2
Joined: Jul 2006
O.P. RE: help me fix my script please
for me, it doesn't.
are you saying that when you run that, it outputs the site's code into the file?
because for me it just outputs "0"

edit: wtf. it works now. i had a different irl in my actual script, but for some reason it works with the msghelp one. woah.

This post was edited on 07-14-2006 at 01:09 AM by AberNStein.
[Image: gybouserbar6hc.gif]
07-14-2006 01:07 AM
Profile PM Find Quote Report
BstrdSmkr
Junior Member
**

Avatar
Earned. Never Given.

Posts: 46
38 / Male / –
Joined: Jul 2006
RE: help me fix my script please
i'm working on a similar project, and on the server i'm working with, it requires some headers to be set.  (request.setHeader("Referer", "chrome://myscript") in my case)  so check to see if that's the case with the server your working with.  if you don't have direct access to the server, the FireFox extension "Live HTTP headers" is a godsend. i'll see if i can find the address to the extention in a min, but its on the official extention site.   hope this helps! :)
07-14-2006 01:45 AM
Profile E-Mail PM Web Find Quote Report
AberNStein
Full Member
***


Posts: 132
Reputation: 2
Joined: Jul 2006
O.P. RE: help me fix my script please
thanks a bunch.
i've gotten quite far now with the script actually.
i'll post another version once i'm really stumped again though.

edit: here we go.
so the purpose of this script is to scrape the scripts forum and toast if there are any new requests. right now it scrapes the forum, and toasts any link with [request] (case insensitive) in it, and then it writes them to a text file. the goal is to have it check that text file before it toasts and then not toast if the thread is already there. i'll add the timer later.
p.s. there's a runtime error on line one or something, i'd rather supress it than figure it out. oh yeah and it toasts and logs twice for each one.
p.p.s. i write ugly code. don't laugh.
code:
function OnEvent_Initialize(MessengerStart)
{
getData();
}

function logging(datum)
{
var fso;
var ForAppending = 8;
var TheFile = MsgPlus.ScriptFilesPath + "\log.txt";
fso = new ActiveXObject("Scripting.FileSystemObject");
var a = fso.OpenTextFile(TheFile, ForAppending, true);
a.WriteLine(datum);
a.Close();
}

var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");

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);
    }
  else
    {
    }
  }
}

function parseIt(htmls)
{
var foo = "";
var oDoc = new ActiveXObject("htmlfile");
oDoc.open();
oDoc.write(htmls);
oDoc.close();
var links = oDoc.getElementsByTagName("a");
for (i=0; i<links.length; i++)
{
foo = links[i].innerHTML.toLowerCase()
if (foo.indexOf("[request]") > -1)
{
MsgPlus.DisplayToast("msghelp.net [request]",links[i].innerHTML,'','OpenSite');
logging(links[i].innerHTML);
}
}
}

function OpenSite(){
new ActiveXObject('WScript.Shell').run('http://shoutbox.menthix.net/forumdisplay.php?fid=39');
}

function OnEvent_Uninitialize(MessengerExit)
{
}


This post was edited on 07-14-2006 at 03:01 AM by AberNStein.
[Image: gybouserbar6hc.gif]
07-14-2006 01:57 AM
Profile PM Find Quote Report
AberNStein
Full Member
***


Posts: 132
Reputation: 2
Joined: Jul 2006
O.P. RE: help me fix my script please
bizzump fo shizzump
[Image: gybouserbar6hc.gif]
07-14-2006 09:00 PM
Profile PM Find Quote Report
Silentdragon
Full Member
***

Avatar
if(life==null && wrists) EmoAlert();

Posts: 148
Reputation: 2
34 / Male / –
Joined: Jun 2006
RE: help me fix my script please
Yeah..I got carried away, but you should be able to tell whats changed.
code:
var TheFile = MsgPlus.ScriptFilesPath + "\\log.txt";
var fso = new ActiveXObject("Scripting.FileSystemObject");
var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");

function OnEvent_Initialize(MessengerStart) {
    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("[request]") > -1 && !checkDupe(links[i].innerHTML)) {
            MsgPlus.DisplayToast("MsgHelp.net [Request]",links[i].innerHTML,'','OpenSite');
            logging(links[i].innerHTML);
        }
    }
}

function OpenSite() {
    new ActiveXObject('WScript.Shell').run('http://shoutbox.menthix.net/forumdisplay.php?fid=39');
}

function OnEvent_Uninitialize(MessengerExit) {
}
07-14-2006 09:42 PM
Profile E-Mail PM Web Find Quote Report
AberNStein
Full Member
***


Posts: 132
Reputation: 2
Joined: Jul 2006
O.P. RE: help me fix my script please
looks good!
thanks.

edit:
quote:
A Runtime Error has occurred.
Do you wish to Debug?

Line: 1
Error: Syntax Error

everything runs though, so if i can supress the error i'd be happy.

This post was edited on 07-15-2006 at 04:40 AM by AberNStein.
[Image: gybouserbar6hc.gif]
07-15-2006 01:26 AM
Profile PM Find Quote Report
« Next Oldest Return to Top Next Newest »


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On