LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   Using curl to post data in a bash script rather than use a web page. (http://www.linuxquestions.org/questions/programming-9/using-curl-to-post-data-in-a-bash-script-rather-than-use-a-web-page-949100/)

pobrika 06-07-2012 05:42 PM

Using curl to post data in a bash script rather than use a web page.
 
Hello,

I am trying to find a way in a bash script to POST data and get the results back from a web page, so I can automate the process.

I understand curl is probably the tool for the job however I can not get the syntax correct.

Using the web developer program in firefox I have found the following the code that is executed from the web page when manually entering a UK town name on the following broadband checking page.

http://www.samknows.com/broadband/exchange_search

Code:

<form method="POST" action="/broadband/exchange_search" id="exchangesearch-form">
<ul class="error_list">

And also this code is used.

Code:

<input maxlength="60" type="text" name="exchange_search[exchange]" id="exchange-input" /> <button id="submit-exchangesearch">Search</button>
I have tried the following curl command but am unsuccessful in getting results.
Code:

curl --request POST 'http://www.samknows.com/broadband/exchange_search' --data "exchange-input=HARLESDEN"
Please can someone show me how this could work, I have read various information on curl but I am having no luck so far.

Thanks.

bigearsbilly 06-07-2012 05:50 PM

your command works for me.

Also wget can do this.

pobrika 06-08-2012 03:18 AM

Hi,

Although I am not getting any errors with the command I do not seem to be getting the results from the POST, I expected to see the HARLESDON and exchange name returned in the results.

Can anyone see or advise what I am doing incorrectly.

Thanks

pobrika 06-08-2012 03:32 AM

I have managed to get it working, seems I was not using the correct field ID in my statement.
the following code finds the Town and prints the Exchange name.

Quote:

curl -s --request POST 'http://www.samknows.com/broadband/exchange_search' --data 'exchange_search[exchange]=HARLESDEN'| grep -i Harlesden | cut -d"/" -f4| cut -d"\"" -f1


All times are GMT -5. The time now is 01:36 PM.