Getting data from a PHP webform into VBScript

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

Post Reply
clickfast
Pro Scripter
Posts: 58
Joined: Wed May 23, 2007 12:04 am

Getting data from a PHP webform into VBScript

Post by clickfast » Tue Jul 03, 2007 11:38 am

Take a look at this PHP website form. Type in "billgates" (nospaces) and it will return a numeric value. http://www.layoutsnetwork.com/id.php

I want to take this PHP web form and basically do the same thing it does in VBscript from MacroScheduler.. The PHP form basically takes the input (in this case 'billgates') and returns a value called 'user id' ... I want to capture the userid and turn it into a vbscript or macroscheduler variable.

I have basically got the script started by using the httprequest to post to the form and get the full html results back which I was then going to parse with a regex query to find the 'userid'.

But this got a little tricky and I'm basically stuck now cause the regex won't work. I have the regex that was used in the PHP code, because my logic was to build a script using httprequest to post to the form and regex the results to extract only the userid.

here is the regex that the site above uses to parse the userid... but I couldn't get it to work in VBscript
preg_match('/\binvite.addfriend_verify&friendID=[0-9]{1,15}\b/is', $result, $found);
Also, here's the code i've built so far. The html request retrieves the entire html response in %useridpost% just fine, but fails at the regex function and i don't know why! :?

Code: Select all

Input>userid,Enter a Popular Name with no spaces to get user id,
Let>PostData=id=%userid%
HTTPRequest>http://www.layoutsnetwork.com/id.php,,POST,PostData,useridpost

MDL>useridpost

//DOES THE REGEX to get USER ID
VBSTART
Function regExSearch(strPattern,str)
  Set regEx = New RegExp ' Create regular expression.
  regEx.Pattern = strPattern ' Set pattern.
  regEx.IgnoreCase = True ' Make case insensitive. Default=False
  Set matches = RegEx.Execute(str)
  List = ""
  regExSearch = Mid(List,1,Len(List)-1)
End Function
VBEND
//Perform the regex search
VBEval>regExSearch(\.invite\.friendID=\.([0-9]{1,15})\),"%useridpost%",useridreg

MDL>useridreg

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Tue Jul 03, 2007 12:52 pm

There are a number of problems with your code:

1. Part of the regExSearch function appears missing - it will always return an error because you have set List to "" and then try to extract a part of it. The bit that concatenates the matches appears missing.

2. Your VBEval statement is invalid - the parameters to be sent to the VBScript function should be quoted and inside parentheses

3. As quote characters denote string delimiters in VBScript you need to double quote any quotes that appear inside a string which you send to VBScript. Carriage Returns and Line Feeds can also throw VBScript, so when sending an unknown string value to VBScript it is always sensible to double quote and replace CR and LF characters.

4. When I did the HTTPRequest I see that the value returned is "User ID: 123456", but your regex seems to be looking for the word "invite" and "friendID" ?

I'm not an expert at regular expressions but looking at the HTML returned I would say you want to find the number that appears after the string "User ID:". So I have used the regular expression "[User Id:]([0-9]{1,15})\b".

So here's my working code:

Code: Select all

Input>userid,Enter a Popular Name with no spaces to get user id,
Let>PostData=id=%userid%
HTTPRequest>http://www.layoutsnetwork.com/id.php,,POST,PostData,useridpost

MDL>useridpost

//DOES THE REGEX to get USER ID
VBSTART
Function regExSearch(strPattern,str)
  Set regEx = New RegExp ' Create regular expression.
  regEx.Pattern = strPattern ' Set pattern.
  regEx.IgnoreCase = True ' Make case insensitive. Default=False
  Set matches = RegEx.Execute(str)
  List = ""
  For each match in matches
     msgbox match.value
  	 List = List & match.value & ";"
  Next
  if List <> "" then
    regExSearch = Mid(List,1,Len(List)-1)
  end if
End Function
VBEND
//Perform the regex search
StringReplace>useridpost,","",useridpost
StringReplace>useridpost,CR,,useridpost
StringReplace>useridpost,LF,,useridpost

VBEval>regExSearch("[User Id:]([0-9]{1,15})\b","%useridpost%"),useridreg

MDL>useridreg
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

clickfast
Pro Scripter
Posts: 58
Joined: Wed May 23, 2007 12:04 am

Post by clickfast » Thu Jul 05, 2007 12:53 am

Thanks Marcus! I will try and report back! Thanks again! This is the best support forum i've ever used. All the experts are fast and always helpful!!

Kudoos!!!!!!!! :lol:

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts