cURL / Mailing Lists / curl-users / Single Mail

curl-users

Re: simulate post data on html form

From: Jochen Hayek <Jochen+curl_at_Hayek.name>
Date: Wed, 14 Feb 2007 21:43:58 +0100

>>>>> "PB" == Philippe Baudry writes:

    PB> hi

    PB> emulation of html form filling with curl seems to us very interesting;
    PB> however i can't run this functionnality correctly

    PB> if we consider a very simple exemple as the input of a search criteria
    PB> in the google form

    PB> if i want to simulate the input of "red house" by exemple,
    PB> i have tryed these simple syntaxes without success

Have you actually looked at the HTML source?
Do you have the faintest idea of how the form looks,
that you want to get filled?
And how the form fields including the hidden ones are named?

    PB> curl --proxy clprox:80 --url http://www.google.fr -d "Recherche
    PB> Google"="red house"

    PB> or

    PB> curl --proxy clprox:80 --url http://www.google.fr -F "Recherche
    PB> Google"="red house"

    PB> could you give me a curl syntax which runs correctly for this exemple

Well, first I started LiveHTTPHeaders within Firefox
in order to get the traffic HTTP traffic displayed.

That is shortcut to find out,
how you can automate the entry of "red house" to the search field.

And this is what I got displayed:

    http://www.google.fr/search?hl=fr&q=red+house&btnG=Recherche+Google&meta=

Well, either you take it as it is,
and this is obviously a valid URL,
and retrieving this URL, just as it is, simply works.

How did all the '+'-s get in their?
Maybe some JavaScript code?

An alternative is to take the URL before the '?',
and then cut the remainder into pieces.
As you probably know, the remainder is a list of form field assignments,
the list member being separated by '&'.

But I am sure, you came across TheArtOfHttpScripting, when you thought about how to do this here, right?

TheArtOfHttpScripting comes with curl -- may I suggest you read it in order to improve your understanding?

    curl --proxy clprox:80 --url http://www.google.fr/search \
        --data-ascii hl=fr \
        --data-ascii q=red+house \
        --data-ascii btnG=Recherche+Google \
        --data-ascii meta=

Whatever you do:
reading the HTML code and / or running LiveHTTPHedaers -- this is some reverse engineering.
And if they are going to change the HTML, they will not tell you beforehand.
And any program depending on the HTML will break.
Received on 2007-02-14