Using HTTPRequest to post to Webform and filtering results??

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

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

Using HTTPRequest to post to Webform and filtering results??

Post by clickfast » Thu Jun 14, 2007 4:46 am

I've searched the forum and didn't find what i need.

I am using an INPUT fuction to get input from a user and post the INPUT to a webform using HTTPRequest and get the response back and put it into a variable.

But the results variable contains the entire html for the webpage and I only want the result from the web form - not the rest of the HTML.. (e.g. I only want the "answer" that the webform gives based on the users response).

Any ideas?

User avatar
jpuziano
Automation Wizard
Posts: 1085
Joined: Sat Oct 30, 2004 12:00 am

Re: Using HTTPRequest to post to Webform and filtering resul

Post by jpuziano » Thu Jun 14, 2007 4:41 pm

Hi clickfast,
clickfast wrote:But the results variable contains the entire html for the webpage and I only want the result from the web form - not the rest of the HTML.. (e.g. I only want the "answer" that the webform gives based on the users response).

Any ideas?
I believe the "answer" you are seeking is buried within your results variable so build yourself some code to parse it. I don't know exactly what your variable contains but let's say it contained these characters somewhere within it:
  • The Answer Is: 42
- Use the Position> command to find the starting position of "The Answer Is: " within the variable
- Add one to that starting position, save value in variable "answer_char_start"
- Use the MidStr> command to extract a substring starting at char position answer_char_start and set the length to long as you need... 2, 4, 10, 100... whatever the max length of your "answer" might be... store it in a new variable "answer"
- Now parse your answer variable to clean it up based on whatever rules you can come up with. Perhaps an ending HTML tag always appears right after the answer text. If so, do the same as above only find the starting char position of that HTML tag, minus 1 from that number and now that number is the length of just your answer... so extract another substring from "answer" and this time, it will contain only your answer, nothing else.

I hope this was helpful. If you still have trouble with this and want further help, post all or a section of the text in your "results variable" and I'm sure someone here can give you further tips on how to best parse it.
jpuziano

Note: If anyone else on the planet would find the following useful...
[Open] PlayWav command that plays from embedded script data
...then please add your thoughts/support at the above post - :-)

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

Re: Using HTTPRequest to post to Webform and filtering resul

Post by clickfast » Thu Jun 14, 2007 7:27 pm

Thanks jpuziano... will give this a try
jpuziano wrote:Hi clickfast,
clickfast wrote:But the results variable contains the entire html for the webpage and I only want the result from the web form - not the rest of the HTML.. (e.g. I only want the "answer" that the webform gives based on the users response).

Any ideas?
I believe the "answer" you are seeking is buried within your results variable so build yourself some code to parse it. I don't know exactly what your variable contains but let's say it contained these characters somewhere within it:
  • The Answer Is: 42
- Use the Position> command to find the starting position of "The Answer Is: " within the variable
- Add one to that starting position, save value in variable "answer_char_start"
- Use the MidStr> command to extract a substring starting at char position answer_char_start and set the length to long as you need... 2, 4, 10, 100... whatever the max length of your "answer" might be... store it in a new variable "answer"
- Now parse your answer variable to clean it up based on whatever rules you can come up with. Perhaps an ending HTML tag always appears right after the answer text. If so, do the same as above only find the starting char position of that HTML tag, minus 1 from that number and now that number is the length of just your answer... so extract another substring from "answer" and this time, it will contain only your answer, nothing else.

I hope this was helpful. If you still have trouble with this and want further help, post all or a section of the text in your "results variable" and I'm sure someone here can give you further tips on how to best parse it.

User avatar
jpuziano
Automation Wizard
Posts: 1085
Joined: Sat Oct 30, 2004 12:00 am

Re: Using HTTPRequest to post to Webform and filtering resul

Post by jpuziano » Thu Jun 14, 2007 8:05 pm

clickfast wrote:Thanks jpuziano... will give this a try
Excellent, let us know how you do... and if you get it working, please consider posting your code for the benefit of other users as this seems like something of general interest.

Thanks and take care
jpuziano

Note: If anyone else on the planet would find the following useful...
[Open] PlayWav command that plays from embedded script data
...then please add your thoughts/support at the above post - :-)

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