Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

IE/vbs Automation start

Status
Not open for further replies.

Rob6000

Technical User
Feb 2, 2003
1
US
Hi, I'm just starting to use Windows scripting and could use some basic help to get me jump-started. (I wish I had known about it for a previous project).

I need to write a script to perform some data retrieval from a web site. I was looking at the iOpus macro package, but for anything complicated they require wsh coding, so it seems to me that I might as well do the whole thing in wsh/vbscript. I'm looking for basic examples and info...

Here's what I'm trying to do. I need to go to a site, fill in a form (so I need basic DOM information for filling in a form field and pressing submit), navigate through a link, and then if another link is on the page navigate through that one as well (otherwise stop). Then write out a note to a status file.

The site requires cookies for authentication, so I assume that I need to script Internet Explorer, though I was also looking at using WinHTTP directly (does that support cookies?).

Thanks for any info!

-Rob
 
Rob,

1) Filling in the form.
Although it may be possible with VBS to actually "fill in" the form fields and "submit" the form, I doubt it. Even if it is possible, it's not the way you want to do it. The first thing you want to find out is the method of the form. Does it use GET (Querystring) or POST (form post). If it uses GET, then just send mimick the querystring and send it to the page referenced in the ACTION tag of the form. That's simple. If it uses Method POST then you have to mimick a form post, which is a bit more complicated. Research the XMLHTTP object to do this. You will need to do this using ASP Code executed via a browser using IIS.

2) Clicking on a link.
I know it's possible to script IE, but I've only seen it done in .NET. Depending on the functionality and difficulty in scripting IE, this may or may not be the best way to go about it. What you could do is:

A) If the link you want to click on never changes, just hardcode the link.

B) If the link does change, I'd do this:

Actually save a copy of the webpage to your PC. Then open that using FSO and pull out the <a href> tag that you want to click on. The best, most efficient way to do this would be to use Regular Expressions, although I'm not sure how familier you are w/ JScript. Otherwise you can use the instr() function. That page will probably have more then one link, so you'll have to be creative on how you go about selecting the appropriate one. After you pull the link from the page you can save that page to your server and perform the same task to see if there is a link on that page you need to follow or if you can just stop.

3) Use FSO to write the file you want.

4) Cookies. Look at the form that it uses for authentication. It probably uses the POST method. It would be stupid not to. So, you'll need to use XMLHTTP to fake another form post, and voila you've got yourself a cookie. If the website has a &quot;remember me&quot; option I would reccomend using that, then checking to see if that cookie exists on your machine before executing this function. (Use FSO to see if the cookie exists)

There may be other ways to do this; there may be better ways; but this is how I would do it. Good luck :)
 
If you can't script the whole thing using IE objects try this tool - which I have used with Scripts to Log me into websites and perform actions.


It is freeware and very easy to use. Also look at Sendkeys command if you don't fancy using this.

Cheers
Sunny
 
Rob, I have the same need it... Could you resolve your issue?

Regards
 
The WinHTTP object can handle both GET and POST, and it will handle session cookies but it can't persist cookies.

For reasons we won't go into it isn't marked as scriptable in IE. It should work fine from a WSH script or HTA though.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top