Programmers - help me win a contest!

Ok, here’s the deal:

A website is holding a weekly contest in which you are rewarded for correctly predicting a pitcher’s performance in his next start.

There are four text boxes: hits, walks, strikeouts, and earned runs. After you have filled out the boxes with your guess and have provided your contact information, you hit “send”. This sends the website your guess and gives you a confirmation page.

Lame contest, right? Here’s where it gets interesting: they explicitly state that you can enter the contest up to 100 times each week. The programmer in me saw this and started drooling…this will be easy, I figured. All I have to do is set “tolerance” values (i.e. I think the pitcher will have 3-6 hits, 0-1 walks, 4-8 strikeouts, 2-4 earned runs). Then I just set up a program that will simply run 4 nested loops to bang out every permutation of my guesses.

Of course, I could manually enter the 100 values, changing one number each time. But that’s no fun :slight_smile:

So here’s my question: how can I write a program that will do the grunt work for me? I took a look at the source code of the page, but that didn’t show me anything interesting, and I don’t know any Perl. I’m learning Java, but I’ve only gotten to the “Hello World” stage. The only thing I can think of would be to write a Visual Basic program that just uses SendKeys() to send the text to the text boxes, hits enter for me, waits a few seconds, sends “alt+left” to go back, types in the new set of numbers, sends again, and so forth.

This seems to be a terribly ineligant and inefficient way to do it, though. I know people write little programs to spam voting scripts and such, but in this case, something like that would actually be legitimate and wouldn’t violate the rules of the contest. Any thoughts on how I could do it, aside from my horrible VB method?

heck, you can probably do it in javascript.
1)Copy the form into a new html page, write a function to put in values then submit.

2)Write another function to increment the values according to your loops, and call the first function.

3)put a button on the page which calls the looping function. press it.
This could fail in 2 ways: They might have it set up to check the referrer tag of the submission, in which case nothing outside their domain will work, or the submit() might cause you to go to another page, without executing the rest of the loops. The second problem can probably be gotten around with some creative work with frames.

If the page is a GET page (e.g. the url has &s and =s and stuff like http://www.foo.bar/pitcher.pl?hits=3&walks=4) I’d do it in perl (or even csh) invoking lynx. Something like


for ($hits = $minHits; $hits <= $maxHits; $hits++) {
  for ($walks = $minWalks; $walks <= $maxWalks; $walks++) {
    (more for loops as needed)
      $commandString = "lynx http://www.foo.bar/pitcher.pl?hits=$hits&walks=$walks&[...]";
      system($commandString);
    }
  }
}

If the page is POSTed, then I would either use TheNerd’s approach if I felt like finally learning javascript, or I’d use perl and open a direct socket connection to the server and start talking HTTP. That way you can also get around the referrer problem TheNerd mentions by coding in whatever HTTP headers you want.

This approach sounds like it might be too geeky for you, but it sure would be fun.

-Doug

Well, the page is indeed POSTed.

I copied the form onto a blank web page and it seems to work just fine without any sort of verification problems.

I guess this is the part where I would add my own button that would run my little loop and send out a 100 submissions in a few seconds, but unfortunately I still don’t know javascript any better than I did yesterday :frowning:

Anyone know any good resources on the web where I can pick up the bare minimum I need to know in order to do this? All I want to do is run a few loops to change the values in some text boxes, and to send the form out.

Thanks,

-Outrider

How about this? It only works in IE, but all you have to do is add your own form and loops and change the method to POST. Making it work in netscape is probably doable, but not worth the trouble (netscape is much more difficult to useful stuff in with javascript / DHTML). For a quick hack, requiring IE shouldn’t be too much of a burden.

Note that it opens a window for each request, so if you have lots of permutations, you might kill your system. In that case, you could uncomment the window.alert line which is right after the form.submit(), and change target="_blank" to target=“bogus” down on the form attributes. This will make it open a new window to submit the form with, then put up a dialog that says “hey!” until you dismiss it, and then submit the form again in the new window with the next set of values, etc. You’ll have to hit enter a whole bunch of times, but that’s life. To avoid that, you would have to figure out how to poll the submitted document’s status and wait until you know it’s been submitted before closing the window. Sounds like work.

douglips’ suggestion is another one I’ve used, but make sure to use the “-source” option to lynx and redirect the output to /dev/null. That way you don’t end up in the interactive lynx user interface.

And a final method I’ve used. Write a shell script which does this:

querystring=some cmd to generate the querystring
length=echo $querystring | wc -c

echo POST /baseball.cgi HTTP/1.0
#echo Referer: add this if they’re smart and require it
echo “Content-length: $length”
echo “”
echo $querystring

Then you pipe this to “nc” (search the web for a package called “netcat” to get this) with the web server and port number on the command line. POST-o-rama.

Oh, forgot to mention. Here’s a good JS reference: http://developer.netscape.com/docs/manuals/js/client/jsref/index.htm

You can send POSTed forms with the LWP::* modules in Perl.

So? Didja win yet? :slight_smile: You don’t have to share the prize, but you do have to let us know whether any of our suggestions helped…