LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
LinkBack Search this Thread
Old 06-07-2012, 05:42 PM   #1
pobrika
Member
 
Registered: Jan 2008
Location: Bournemouth, UK
Distribution: Mint, #!, Fedora, Redhat, Centos
Posts: 64

Rep: Reputation: 18
Question 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.
 
Old 06-07-2012, 05:50 PM   #2
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: FreeBSD, Debian, Mint, Puppy
Posts: 3,269

Rep: Reputation: 165Reputation: 165
your command works for me.

Also wget can do this.
 
Old 06-08-2012, 03:18 AM   #3
pobrika
Member
 
Registered: Jan 2008
Location: Bournemouth, UK
Distribution: Mint, #!, Fedora, Redhat, Centos
Posts: 64

Original Poster
Rep: Reputation: 18
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
 
Old 06-08-2012, 03:32 AM   #4
pobrika
Member
 
Registered: Jan 2008
Location: Bournemouth, UK
Distribution: Mint, #!, Fedora, Redhat, Centos
Posts: 64

Original Poster
Rep: Reputation: 18
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
 
  


Reply

Tags
bash, curl, scripting, shell script


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I execute a bash script from a link on a web page? Is there any way to do this digilifellc Linux - Desktop 6 03-11-2011 02:56 AM
[SOLVED] How to execute bash script from web page mustkill Linux - Server 16 05-20-2010 11:01 AM
How do I execute a bash script from a link on a web page? Is there any way to do this digilifellc Linux - Desktop 5 03-10-2010 11:24 AM
Wget or cURL code for checking changes to a web page? ewingtux Programming 2 12-16-2008 04:46 PM
shell script to submit web POST data? Yalla-One Programming 5 11-03-2006 04:21 AM


All times are GMT -5. The time now is 07:49 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration