 |
VBScript For questions and discussions related to VBScript. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the VBScript section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|

January 20th, 2009, 04:43 AM
|
Registered User
|
|
Join Date: Jan 2009
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Using VBScript to Fill Out a Web Form
Peace all, I am currently trying to use VBScript to fill out a web form (and submit it).
For example, I am using this script.
Code:
Set IE = CreateObject("InternetExplorer.Application")
set WshShell = WScript.CreateObject("WScript.Shell")
IE.Navigate "http://mylogin.page"
IE.Visible = True
Wscript.Sleep 6000
IE.Document.All.Item("fld_userName").Value = "adley"
IE.Document.All.Item("fld_password").Value = "password"
WshShell.AppActivate "IE"
WshShell.SendKeys "{ENTER}"
My problem is this.
The script above works for most pages, but there are a few exceptions that I hoped someone in this forum would help me.
1. If the connection is sooo slow, the "Sleep" line above is not that effective. Does anyone know a better way, such as a "wait until page completely loaded" function?
2. I am using SendKeys above, but for cases where the web page doesn't necessarilly accept ENTER after filling out the password, I need something else. I encounter this for a web page requiring me to select a value from a drop-down box and click the "Log On" button afterward. I can specify the value to be selected, but sending ENTER (or TAB then ENTER) was useless. I don't know how to set a focus to a web object/field using VBScript.
Any help would be much appreciated. Thanks.
Last edited by adley; January 20th, 2009 at 04:48 AM..
|

January 20th, 2009, 06:43 AM
|
Registered User
|
|
Join Date: Jan 2009
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Peace all,
Never mind.
Solved it.
Thanks.
|

April 17th, 2009, 01:31 AM
|
Registered User
|
|
Join Date: Apr 2009
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
QUICK QUESTION !!!!!
I'm trying to automate posting to craigslist with my ad that I normally have to post manually (which is a pain in the bottom!). My issue is that I can't get to the text boxes to fill them out in Craigslist since the "{Tab}" is skipping some of the fields. So I used the following code below:
Set IE = CreateObject("InternetExplorer.Application")
IE.Navigate " https://post.craigslist.org/ahn/S/msg/none/x"
IE.Visible = True
Wscript.Sleep 4000
Document.All.Item("?").Value = "Whatever Message You Want"
IE.Document.All.Item("?").Click
Can someone please fill in the "?" to help answer the question & make the cursor land in the boxes?
Here's the Craigslist page that I'm trying to automate:
https://post.craigslist.org/atl/S/msg/none/x
|

April 17th, 2009, 02:16 AM
|
Friend of Wrox
|
|
Join Date: Jun 2008
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
|
|
A better way to do this would probably be to use the MSXML2.ServerXMLHTTP object to *fully* automate the process, so that the browser window doesn't even pop up.
|

April 17th, 2009, 12:24 PM
|
Registered User
|
|
Join Date: Apr 2009
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
???
Quote:
Originally Posted by Old Pedant
A better way to do this would probably be to use the MSXML2.ServerXMLHTTP object to *fully* automate the process, so that the browser window doesn't even pop up.
|
Thanks for you quick reply. Well I'm new to VBScript & surprised that with what I have already learned, but could you please show me the exact code example and display it the way that I did above so that I will know exactly how to use it. Effective learning. Thanks. 
|

April 17th, 2009, 02:38 PM
|
Friend of Wrox
|
|
Join Date: Jun 2008
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
|
|
Ugh...I should have looked at that URL you posted before opening my mouth.
The problem is, Craiglist apparently generates a unique <FORM> for each and every posting.
For example, I hit the URL once and got a <FORM> that looked like this:
Code:
<form id="postingForm" action="/atl/S/msg/none/x/ERJkQMOKlP0yshV8/y2mi6"
method="post" enctype="multipart/form-data">
<input type="hidden" name="postingKey" id="postingKey" value="ERJkQMOKlP0yshV8">
<input type="hidden" name="test" id="test" value="y2mi6">
... and so on ...
So then I hit the same URL again and got a <form> that looked like this:
Code:
<form id="postingForm" action="/atl/S/msg/none/x/PMAzNiDklEgG23zH/i2w9n"
method="post" enctype="multipart/form-data">
<input type="hidden" name="postingKey" id="postingKey" value="PMAzNiDklEgG23zH">
<input type="hidden" name="test" id="test" value="i2w9n">
... and so on ...
So it's not at all like filling out a <form> on most sites. Unfortunately.
I think it still could be done, but it's probably a lot more work than the way you were starting to go. So I sincerely apologize for putting both feet firmly between my teeth.
Incidentally, that URL doesn't even produce a response from an MSIE 6 browser! So obviously Craigslist also customizes the URLs to match a specific browser type! Wow. I'm pretty sure I *could* do it the way I suggested, but it's at least a couple of days' work. (With most sites, it's 30 minutes or so.)
|

April 17th, 2009, 05:18 PM
|
Registered User
|
|
Join Date: Apr 2009
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Just To Make Sure You Understood.....
Please watch this video to see in more detail of what it is that I'm trying to do:
http://www.youtube.com/watch?v=Vv0yiAJiAPY
Quote:
Originally Posted by Old Pedant
Ugh...I should have looked at that URL you posted before opening my mouth.
The problem is, Craiglist apparently generates a unique <FORM> for each and every posting.
For example, I hit the URL once and got a <FORM> that looked like this:
Code:
<form id="postingForm" action="/atl/S/msg/none/x/ERJkQMOKlP0yshV8/y2mi6"
method="post" enctype="multipart/form-data">
<input type="hidden" name="postingKey" id="postingKey" value="ERJkQMOKlP0yshV8">
<input type="hidden" name="test" id="test" value="y2mi6">
... and so on ...
So then I hit the same URL again and got a <form> that looked like this:
Code:
<form id="postingForm" action="/atl/S/msg/none/x/PMAzNiDklEgG23zH/i2w9n"
method="post" enctype="multipart/form-data">
<input type="hidden" name="postingKey" id="postingKey" value="PMAzNiDklEgG23zH">
<input type="hidden" name="test" id="test" value="i2w9n">
... and so on ...
So it's not at all like filling out a <form> on most sites. Unfortunately.
I think it still could be done, but it's probably a lot more work than the way you were starting to go. So I sincerely apologize for putting both feet firmly between my teeth.
Incidentally, that URL doesn't even produce a response from an MSIE 6 browser! So obviously Craigslist also customizes the URLs to match a specific browser type! Wow. I'm pretty sure I *could* do it the way I suggested, but it's at least a couple of days' work. (With most sites, it's 30 minutes or so.)
|
|

April 17th, 2009, 07:34 PM
|
Friend of Wrox
|
|
Join Date: Jun 2008
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
|
|
I don't think the form, per se, is encrypted. I do think that the *names* of the form fields and the values of certain HIDDEN form fields are encrypted, and that they use that indeed as a way to ensure that you can't just keep submitting the same <form> over and over. Each post you make must be made with a new <form> that you get from them.
And the form field names change on each reload of the page. So your VBS code would have to scan all the fields and figure out, by position, which one is doing what. So you can't just "fill in the ?" as somebody suggested. You first have to figure out what ? is for this particular incarnation of the <form>.
No, I don't know how to do that using the MSIE object scripted by VBS. I think I could do it by "screen scraping", using ServerXMLHTTP, as I suggested. But it's not a trivial task and would take several hours. With no guarantees it works, at the end.
I looked at their JS library and didn't *see* anything doing client-side encryption. Doesn't mean it's not there. But I don't see why it would matter if there is, if you are indeed invoking the browser itself.
I think it's mainly just the field names and then hidden form field values that have to agree to constitute a valid post, so far as their protection software is concerned.
|

April 17th, 2009, 09:38 PM
|
Registered User
|
|
Join Date: Apr 2009
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Try This Out !!!
Well I understand that you believe the codes change with each download, but I am %110 sure that this can be done as well. Maybe not the same exact source code that I displayed earlier, but there are plenty of software apps out there that can automate posting to Craigslist with 1 simple click of a button. I know that some of those particular web bots were designed in VB 2008.
Here's another VBScript that I wrote that works sometimes, but sometimes just isn't good enough. Try it out and see if you can tamper it into shape:
Code:
set a = createobject("wscript.shell")
a.run "https://post.craigslist.org/sfo/S/msg/sfc/9"
wscript.sleep (8000)
a.SendKeys "{TAB 10}"
wscript.sleep (2000)
a.sendkeys ("Whatever ad Title that you want")
a.SendKeys "{TAB}"
a.sendkeys ("10.00 !!!")
a.SendKeys "{TAB}"
a.sendkeys ("[email protected]")
a.SendKeys "{TAB}"
a.sendkeys ("[email protected]")
a.SendKeys "{TAB 2}"
a.sendkeys ("whatever ad that you want***BZ***: http://store.payloadz.com/results/st...d-results.html")
wscript.sleep (2000)
a.SendKeys "{TAB}"
wscript.sleep (2000)
a.SendKeys "{Enter}"
wscript.sleep (4000)
a.SendKeys "{TAB 10}"
wscript.sleep (2000)
a.SendKeys "{Enter}"
wscript.sleep (4000)
a.SendKeys "{TAB 15}"
wscript.sleep (2000)
a.SendKeys "{Enter}"
call msgbox("Finished")
wscript.quit
This is a pretty cool WEBBOT most of the time, but most of the time isn't good enough either. ;oD
It will get you all the way to the CAPTCHA point most of the time & then you will see the finished box.
**** Don't click any windows while it's in process ***
Please try your best to fix this script to perfection.... Thanks !!!
Quote:
Originally Posted by Old Pedant
I don't think the form, per se, is encrypted. I do think that the *names* of the form fields and the values of certain HIDDEN form fields are encrypted, and that they use that indeed as a way to ensure that you can't just keep submitting the same <form> over and over. Each post you make must be made with a new <form> that you get from them.
And the form field names change on each reload of the page. So your VBS code would have to scan all the fields and figure out, by position, which one is doing what. So you can't just "fill in the ?" as somebody suggested. You first have to figure out what ? is for this particular incarnation of the <form>.
No, I don't know how to do that using the MSIE object scripted by VBS. I think I could do it by "screen scraping", using ServerXMLHTTP, as I suggested. But it's not a trivial task and would take several hours. With no guarantees it works, at the end.
I looked at their JS library and didn't *see* anything doing client-side encryption. Doesn't mean it's not there. But I don't see why it would matter if there is, if you are indeed invoking the browser itself.
I think it's mainly just the field names and then hidden form field values that have to agree to constitute a valid post, so far as their protection software is concerned.
|
|

April 18th, 2009, 12:48 AM
|
Friend of Wrox
|
|
Join Date: Jun 2008
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
|
|
Well, I'm done here. Maybe somebody else will comment.
|
|
 |