mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Feb 2003
Posts: 32
C
Ameglian cow
OP Offline
Ameglian cow
C
Joined: Feb 2003
Posts: 32
Hello, I have this code and I want to see the results that $com(gp).result returns, which has 1000+ characters. How could I see what it returns?

Code:
alias getpage {
  .comopen gp Microsoft.xmlHTTP
  !.echo -q $com(gp,Open,1,bstr,Get,bstr,$1,bool,false)
  !.echo -q $com(gp,Send,1)
  !.echo -q $com(gp,responseText,2)
; $com(gp).result contains more that 1000 characters...
  bwrite c:\temp.txt -1 -1 $com(gp).result
  .comclose gp
}


Thx

Last edited by cerberus_gr; 13/02/05 05:43 PM.
Joined: Feb 2004
Posts: 2,019
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2004
Posts: 2,019
Well,

there's no way around this that I know, the only thing you can do is turn this script into a vbscript snippet, and run it with wscript.shell's run method (if it is required that the output is written to file before any other processing).

Once your object.responsetext is filled with the html source, you can write it to a file using the FileSystemObject, where this +/-940 char limit doesn't exist.

So you'll end up with a text file with the requested data from the webpage.

I suppose you know how to do all this, if not let me know and I'll post an example.

Btw you know that mIRC supports sockets, right?

Greets


Gone.
Joined: Feb 2003
Posts: 32
C
Ameglian cow
OP Offline
Ameglian cow
C
Joined: Feb 2003
Posts: 32
Yes but mirc sockets doesn't support ssl and as i read in some topics over here, with this way i could "visit" a https webpage.

Could you write an example because i know only a little vbs?

Thx

Joined: Feb 2004
Posts: 2,019
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2004
Posts: 2,019
Before trying this code there are a few things to take into consideration:

  • This method does not work on all sites, in my tests, it worked fine on sites like microsoft.com, winamp.com, but said permission denied when trying on google.com.
  • The url to enter must be either an absolute URL, such as "http://Myserver/Mypath/Myfile.asp", or a relative URL, such as "../MyPath/MyFile.asp". This means you type http://www.microsoft.com/ instead of www.microsoft.com. It will not work if the url isn't complete!
  • The IXMLHTTPRequest open Method supports accessing secure sites that requires authentication. It accepts two optional arguments for a user name and password.
  • More information can be found on the web, and there is some documentation on MSDN which can be found here. There should be plenty of information for you to be able to make your script.
  • I didn't add any error checking since this snippet is really only for educational purposes, and not to be used in scripts.
  • Right now the snippet waits to finish until the source is downloaded, meaning if it takes 5 seconds, the snippet is paused for 5 seconds. That's because I use wscript.shell's run method. If it doesn't really matter when the html is there, then you could just use the built-in /run, though you won't be exactly sure then when the html actually arrived.
  • I'm not a programmer, so I can't guarantee this is a good way to go about this.

Usage: $gethtml(URL,path to output file)

Example: //echo -a $gethtml(http://www.winamp.com/,$mircdiroutputhtml.txt)

Code:
alias gethtml {
  if $2 == $null { return }
  var %a = $ticks $+ .vbs, %b = aline @@
  window -h @@
  %b set xml = createobject("Microsoft.XMLHTTP") 
  %b xml.open "GET", " $+ $1", false 
  %b xml.send 
  %b do until xml.readystate = 4 : wscript.sleep 50 : loop
  %b set fso = createobject("scripting.filesystemobject")
  %b set file = fso.createtextfile(" $+ $2", True)
  %b file.writeline xml.responsetext
  %b file.close
  savebuf @@ %a
  close -@ @@
  .comopen %a wscript.shell
  if !$comerr {
    .comclose %a $com(%a,Run,1,bstr,%a,uint,0,bool,true)
    echo -ac info gethtml: retrieved source from $1 saved to $2
  }
  .remove %a
}


Be sure to check that MSDN link, it contains everything you need.

Hope this was helpful,

Greets


Gone.
Joined: Feb 2003
Posts: 32
C
Ameglian cow
OP Offline
Ameglian cow
C
Joined: Feb 2003
Posts: 32
thx you are great smile

Although it returns error and doesn't work frown

Code:
Script:    name
Line:      3
Char:     1
Error:     0x800C0008
Code:     800C0008
Source: (null)


If you could help me smile

Joined: Feb 2004
Posts: 2,019
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2004
Posts: 2,019
Well it would help if you'd tell me what site you tried, since indeed, as I said it doesn't work on a lot of sites. I looked up that error code and on a site I found it has the following meaning: "Cannot download the information you requested."

Sometimes even if it got the html source, it wouldn't write it to a file, I'd get an error on the line where it wants to write the source to the file, I don't know why, perhaps it's some sort of limitation.

The weird thing was that I could put a "wscript.echo xml.responsetext" and it would show the source, but somehow doesn't want to write it.

Anyway, show me what site you tried and if you have changed anything in the code.

Greets


Gone.
Joined: Feb 2003
Posts: 32
C
Ameglian cow
OP Offline
Ameglian cow
C
Joined: Feb 2003
Posts: 32
this is the vbs file

set xml = createobject("Microsoft.XMLHTTP")
xml.open "GET", "http://www.yahoo.com/", false
xml.send
do until xml.readystate = 4 : wscript.sleep 50 : loop
set fso = createobject("scripting.filesystemobject")
set file = fso.createtextfile("D:\f\private\mirc\outputhtml.txt", True)
file.writeline xml.responsetext
file.close

and i take the same error in all sites. Could be a problem with my firewall (zonealarm)?

Joined: Feb 2004
Posts: 2,019
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2004
Posts: 2,019
It worked fine here, using the exact same code as you, but changed the path to d:\mirc\outputhtml.txt

It can be a lot of things really, maybe you have AVG software blocking scripts, your firewall might interfere, you may not have the necessary libraries loaded in your windows etc.

To be honest, I think you should use sockets, that's what they're there for. I'm not an expert on sockets, but I know you can use POST to put in postdata when connecting to a site, you should look into that instead. I wouldn't be surprised at all if you can connect to a secure site.

It's a pitty, I'm kind of bored with scripting right now, if I had the motivation I'd have looked into this more, sorry.

Greets


Gone.
Joined: Feb 2003
Posts: 32
C
Ameglian cow
OP Offline
Ameglian cow
C
Joined: Feb 2003
Posts: 32
Thx a lot for your time smile

I don't think that a simple socket could communicate with https because there is a need for ssl.
I'll try your code more to find what doesn't work with my system.

Thx again smile


Link Copied to Clipboard