You are not logged in.

#1 2009-12-03 12:24:23

Aprz
Member
From: Newark
Registered: 2008-05-28
Posts: 277

[SOLVED] Using wget to submit a form

Edit: Figured out I was using the wrong URL and needed some necessary POST/GET data I wasn't filling out.

Hm, I am trying to be able to submit a form using wget. I am able to actually put data in <textarea> like I want, but I fail to submit it through wget.

I was able to login to the site by cheating a little bit. I came up with two methods to do it, the first one is easy which is just going to ~/.mozilla/firefox/<xxxx>/cookies.sqlite, and converting it to a *.txt. Easy. Or you can do it the slightly more complicated way by going to page you want, typing the url bar javascript:document.write(document.cookie); document.close(); and manually create the cookies.txt file using the information from that. Anyhow, that is how I am able to go into the site without having to submit my username/password in the first place (I kept failing to do that, it didn't even return the page with my username and password typed in like what's going on below). Anyhow, now I am stumped at actually submitting the post I want to. I execute:

wget --cookies=on --keep-session-cookies --load-cookies=cookie.txt --post-data="Post=test" http://www.url-to-the-site.com/

and the end result is:

result.png
^This is what wget returns and what it looks like when I open it in Firefox.^

Which is what it returns. I checked the website and it didn't post it (I expected that since it returns that and not the post itself). I know you can't see it in the image there, but there is a submit button at the bottom of the page.

The form looks something like this (stripped down):

<form action='<url of website>' method='post' name='REPLIER' onsubmit='return ValidateForm()'>
<input type='hidden' name='act' value='Post' />
<input type='hidden' name='s' value='xxxxxx' />
<input type='hidden' name='f' value='24' />
<input type='hidden' name='auth_key' value='xxxxxx' />

<input type='hidden' name='CODE' value='09' />
<input type='hidden' name='t' value='41457' />
<input type='hidden' name='p' value='514135' />
<input type='hidden' name='st' value='0' /><br />
<input type="submit" name="submit" value="Add Reply" tabindex='4' class='forminput' accesskey='s' />
<input type="submit" name="preview" value="Preview Post" tabindex='5' class='forminput' />
</form>

Any idea?





**Meh, in my experience of posting here, helpers/answers/whatever usually like an answer of why I have to do this the difficult way instead of just going there and posting myself in the first place (after all, it might help you answer the question). Well, we are playing a little game in there and I wrote a little script that keeps track of the points in the game... It makes a nice little pretty table that I use cron to update every hour, but then people have to wait until I actually post the table to see how they are doing in the game. So... I'd like to have it automatically post each update.

Then I have a second use: If I am able to successfully post this, I am trying to get into a class at college. I already wrote a script that detects whether there is available space or not in the class. I'd like to be able to have it monitoring for an open spot in the class and if so... to check it [x] and submit so I can get in the class without having to sit at the computer refreshing all day hopelessly. big_smile

And plus I learned programming, how to use so much utilities to do whatever... why stop now? tongue

In advance, thank you for taking the time to help me with this.

Last edited by Aprz (2009-12-05 11:25:51)

Offline

#2 2009-12-03 14:05:49

Shapeshifter
Member
Registered: 2008-03-11
Posts: 230

Re: [SOLVED] Using wget to submit a form

have you considered using curl? Submitting forms in curl is very easy. and saving cookies is easy as well.

for example:

curl -s -D lccookie -d "login=$login&password=$password" http://somepage.com/index.php?

to log in (which also is submitting a form), and

curl -s -b lccookie -e http://somepage.com/index.php --data-urlencode "EntryEffect%3A=$entryeffect" --data-urlencode "ClosingEffect%3A=$closingeffect" --data-urlencode "Color%3A=$colour" --data-urlencode "messagefield=$OPTARG" -d "Submit=Submit" http://somepage.com/index.php?

to reuse the cookie and submit a form. (This is from a script I wrote that sends formated messages to a page which shows them on a ledbar.)

Last edited by Shapeshifter (2009-12-03 14:09:36)

Offline

#3 2009-12-03 14:48:13

Aprz
Member
From: Newark
Registered: 2008-05-28
Posts: 277

Re: [SOLVED] Using wget to submit a form

I actually have tried using curl. I believe wget --post-data and curl -d are pretty much the same. I was able to use my cookies.txt file using -b like you have. I just cannot seem to submit on this website. As I showed above, that's what the form is like (excluding the <textarea>, I forgot to copy and paste that). The returning page will be like the picture, but it doesn't submit it... That was true with both curl and wget.

The --data-urlencode I haven't tried using and don't know what that is so I am going to try that. I need to run off to work now though so I'll be back in a couple of hours (on my break).

Last edited by Aprz (2009-12-03 14:50:03)

Offline

Board footer

Powered by FluxBB