473,769 Members | 2,501 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

using cgi form via http and extracting results

I would like to use an already existing online service (currency
converter) basically consisting of a html form with a few options that
is submitted and returns the results. I really don't know where to start
but I have assumed the following steps need to be taken:

1) Make an http connection to the remote script (http://server/script.cgi)

2) Fill out the html form (1x TEXT and 2x SELECT input fields)

3) Submit the form

4) extract the actual returned result. (using regex or something..)

Any help on which modules to use would be much appreciated!

Jul 18 '05 #1
8 1828
I found a possible solution:
http://wwwsearch.sourceforge.net/ClientForm

bmgx wrote:
I would like to use an already existing online service (currency
converter) basically consisting of a html form with a few options that
is submitted and returns the results. I really don't know where to start
but I have assumed the following steps need to be taken:

1) Make an http connection to the remote script (http://server/script.cgi)

2) Fill out the html form (1x TEXT and 2x SELECT input fields)

3) Submit the form

4) extract the actual returned result. (using regex or something..)

Any help on which modules to use would be much appreciated!


Jul 18 '05 #2
bmgx <bm********@mgl eesonprop.co.za > wrote:
I would like to use an already existing online service (currency
converter) basically consisting of a html form with a few options that
is submitted and returns the results. I really don't know where to start
but I have assumed the following steps need to be taken:

1) Make an http connection to the remote script (http://server/script.cgi)

2) Fill out the html form (1x TEXT and 2x SELECT input fields)

3) Submit the form

4) extract the actual returned result. (using regex or something..)


You don't actually need steps 1 and 2 at all. HTTP transactions are all
completely separate. The results of a form submission are just a URL. If
the form has fields "FromCurren cy", "ToCurrency ", and "Amount", all you
have to do is this:
http://www.currencyservice.com?FromC...unds&Amount=15

You don't have to HAVE the form source in order to submit a request.
--
- Tim Roberts, ti**@probo.com
Providenza & Boekelheide, Inc.
Jul 18 '05 #3
On Mon, 05 Jan 2004 17:39:30 -0800, Tim Roberts wrote:
bmgx <bm********@mgl eesonprop.co.za > wrote:
1) Make an http connection to the remote script (http://server/script.cgi)
2) Fill out the html form (1x TEXT and 2x SELECT input fields)
3) Submit the form
4) extract the actual returned result. (using regex or something..)
You don't actually need steps 1 and 2 at all.


True.
HTTP transactions are all completely separate.
True (ignoring cookies for now).
The results of a form submission are just a URL.
Usually false.

The result of most form submissions is an HTTP POST request, which
contains the URL and form content as separate data.
If the form has fields "FromCurren cy", "ToCurrency ", and "Amount", all
you have to do is this:

http://www.currencyservice.com?FromC...unds&Amount=15
This is only true if the form action is an HTTP GET request, which is a
rather insecure and ugly way to submit form data, and makes it
impossible to submit many kinds of data. HTTP POST is the recommended
method for submitting data to a CGI script.
You don't have to HAVE the form source in order to submit a request.


True. You just need to construct the HTTP POST request correctly.

--
\ "It's a good thing we have gravity or else when birds died |
`\ they'd just stay right up there. Hunters would be all |
_o__) confused." -- Steven Wright |
Ben Finney <http://bignose.squidly .org/>
Jul 18 '05 #4
How would one "create" post data so that I can skip the html form and
access the submission script (in <form method="POST" action="SCRIPT" >)
directly. This is simple if the script uses GET as mentioned, but
unfortunately this is not the case which is the very reason for my dilemma..

Ben Finney wrote:
On Mon, 05 Jan 2004 17:39:30 -0800, Tim Roberts wrote:
bmgx <bm********@mgl eesonprop.co.za > wrote:
1) Make an http connection to the remote script (http://server/script.cgi)
2) Fill out the html form (1x TEXT and 2x SELECT input fields)
3) Submit the form
4) extract the actual returned result. (using regex or something..)


You don't actually need steps 1 and 2 at all.

True.

HTTP transactions are all completely separate.

True (ignoring cookies for now).

The results of a form submission are just a URL.

Usually false.

The result of most form submissions is an HTTP POST request, which
contains the URL and form content as separate data.

If the form has fields "FromCurren cy", "ToCurrency ", and "Amount", all
you have to do is this:

http://www.currencyservice.com?FromC...unds&Amount=15

This is only true if the form action is an HTTP GET request, which is a
rather insecure and ugly way to submit form data, and makes it
impossible to submit many kinds of data. HTTP POST is the recommended
method for submitting data to a CGI script.

You don't have to HAVE the form source in order to submit a request.

True. You just need to construct the HTTP POST request correctly.


Jul 18 '05 #5
Ok it's done right..

import urllib
a = urllib.urlopen( "http://www.suckerservi ce.com/convert.cgi",
"Amount=1&From= EUR&To=USD")
b = a.readlines()
c = open("tempresul t.html","w")

i = 0
d = "********* local copy ******\n\n"
while i < len(b):
d = d + b[i]
i = i + 1

c.write(d)
c.close()
a.close()

bmgx wrote:
How would one "create" post data so that I can skip the html form and
access the submission script (in <form method="POST" action="SCRIPT" >)
directly. This is simple if the script uses GET as mentioned, but
unfortunately this is not the case which is the very reason for my
dilemma..

Ben Finney wrote:
On Mon, 05 Jan 2004 17:39:30 -0800, Tim Roberts wrote:
bmgx <bm********@mgl eesonprop.co.za > wrote:

1) Make an http connection to the remote script
(http://server/script.cgi)
2) Fill out the html form (1x TEXT and 2x SELECT input fields)
3) Submit the form
4) extract the actual returned result. (using regex or something..)
You don't actually need steps 1 and 2 at all.


True.

HTTP transactions are all completely separate.


True (ignoring cookies for now).

The results of a form submission are just a URL.


Usually false.

The result of most form submissions is an HTTP POST request, which
contains the URL and form content as separate data.

If the form has fields "FromCurren cy", "ToCurrency ", and "Amount", all
you have to do is this:

http://www.currencyservice.com?FromC...unds&Amount=15


This is only true if the form action is an HTTP GET request, which is a
rather insecure and ugly way to submit form data, and makes it
impossible to submit many kinds of data. HTTP POST is the recommended
method for submitting data to a CGI script.

You don't have to HAVE the form source in order to submit a request.


True. You just need to construct the HTTP POST request correctly.


Jul 18 '05 #6
bmgx wrote:
Ok it's done right..

import urllib
a = urllib.urlopen( "http://www.suckerservi ce.com/convert.cgi",
"Amount=1&From= EUR&To=USD")
b = a.readlines()
c = open("tempresul t.html","w")

i = 0
d = "********* local copy ******\n\n"
while i < len(b):
d = d + b[i]
i = i + 1

c.write(d)
c.close()
a.close()


Instead of constructing the data string by hand, you can pass a
dictionary or list of 2-item tuples to urllib.urlencod e() and get a
properly formatted string:

my_data = urllib.urlencod e({'Amount':1,' From':'EUR','To ':'USD'}) # or...
my_data = urllib.urlencod e([('Amount',1),(' From','EUR'),(' To','USD')])
a = urllib.urlopen( 'http://www.suckerservi ce.com/convert.cgi', my_data)
Jul 18 '05 #7
Ben Finney <bi************ ****@and-benfinney-does-too.id.au> wrote:
On Mon, 05 Jan 2004 17:39:30 -0800, Tim Roberts wrote:
bmgx <bm********@mgl eesonprop.co.za > wrote:
1) Make an http connection to the remote script (http://server/script.cgi)
2) Fill out the html form (1x TEXT and 2x SELECT input fields)
3) Submit the form
4) extract the actual returned result. (using regex or something..)


You don't actually need steps 1 and 2 at all.


True.
HTTP transactions are all completely separate.


True (ignoring cookies for now).
The results of a form submission are just a URL.


Usually false.

The result of most form submissions is an HTTP POST request, which
contains the URL and form content as separate data.


You are correct. However, in my experience, most handlers that expect POST
data will also accept the same information via GET. That is fortunate,
since it makes it easy to do things the way I suggested.
If the form has fields "FromCurren cy", "ToCurrency ", and "Amount", all
you have to do is this:

http://www.currencyservice.com?FromC...unds&Amount=15


This is only true if the form action is an HTTP GET request, which is a
rather insecure and ugly way to submit form data, and makes it
impossible to submit many kinds of data. HTTP POST is the recommended
method for submitting data to a CGI script.


There is no such "recommendation ". GET is entirely appropriate for many
kinds of information. A currency conversion service such as the one the
O.P. described is a perfect example. There is no need for security in such
a service, and it makes it easy to do canned requests like the one above.
--
- Tim Roberts, ti**@probo.com
Providenza & Boekelheide, Inc.
Jul 18 '05 #8
Basically you have to examine the html source for the page you want to
automate, and figure out how the form works. To do that, you need to
understand html and http, there is no way around it. Maybe someone
here can suggest a good reference for that.

Once you've figured out the form, just use the urllib module to build
and send the appropriate http request.
Jul 18 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
2070
by: Steve | last post by:
Hi All! I wonder if anyone could help me with the underlying logic of a problem I have. At the moment my working pages run like so --------------------------------------------------------- PAGE1: A form which gathers variables and POSTS them on to the next page. PAGE2: This page does a few simple calculations based on the variables gathered on PAGE1 and echoes the results to screen. It also contains a two
10
3678
by: Calvin FONG | last post by:
Dear all, Are there any utility that can be call by python to create self extracting zip file. I'm now using the powerarchiever. But the command line options aren't flexible enough. Basically, I would like to create a self extracting zip with default file path extraction and force over-write. The powerArchiever just don't let me call it unless I'm using the GUI. Any idea, experience and suggestion are welcome. Thank you. -Calvin
3
13827
by: Peter Phelps | last post by:
My problem is as follows: I need automatically iterate through a single field in a table and use the values in the field to create an in-statement. Currently, the character limitation in the "Zoom" feature of the MS Access query builder limits the number of characters I can enter into my In-Statement. As a result, I need to iterate through a particular field (Customer ID Numbers) and use each record as a criteria in a query. I want to...
5
4335
by: Ilan Sebba | last post by:
When it comes to adding records in related tables, Access is really smart. But when I try to do the same using ADO, I am really stupid. Say I have two parent tables (eg Course, Student) and one child table (StudentProgress). The course progress records how a student progresses on a course. I have one course (History) and one student called Maya. I now want to record her grade (64). If I do this in Access using a form, then the form...
3
3972
by: Nathan Bloomfield | last post by:
I am having difficulty with an attempt at setting a recordset based on a string. The code -- Set rsSource = CurrentDb.OpenRecordset("'" & strSourceTable & "'", dbOpenTable) -- results in the following error: "The microsoft could not find the object "vCUSTMR". Make sure the object exists and you spell its name and path name correctly." The tables do exist and are spelled correctly, the recordset "rs" is
4
2387
SHOverine
by: SHOverine | last post by:
I have a 3-part form that I am having trouble with. First part is to select the user group and the week and year that I want to submit results for, this calls the elements that I want to update. The second part is to enter the results and submit them to a MySQL table called results the final part echoes the results. The issue is that my form writes the elements that I called up to the this table before I enter the results and click...
1
2283
by: erick-flores | last post by:
Hello all I have a linked table using ODBC. When I tried to do Count() and Sum() for this linked table (onw of the field in the table is name "total") the form takes forever to gives me the results, like 4 minutes. I am putting a textbox in the footer of my form to get this results. The table has around 1300 records. Is there a better way to get quicker results? I know I can copy the linked table to my local computer and then the
0
2050
by: napolpie | last post by:
DISCUSSION IN USER nappie writes: Hello, I'm Peter and I'm new in python codying and I'm using parsying to extract data from one meteo Arpege file. This file is long file and it's composed by word and number arguments like this: GRILLE EURAT5 Coin Nord-Ouest : 46.50/ 0.50 Coin Sud-E Hello, I'm Peter and I'm new in python codying and I'm using parsying to extract data from one meteo Arpege file.
4
4934
by: eeb4u | last post by:
I am connecting to MS SQL 2000 from Red Hat EL4 using freetds and currently running queries to get counts on tables etc. When running SELECT queries I notice that the data returns and I have to parse out the field names etc. Is there any easier way to extract the data in a comma separated form? I was thinking of reading the contents into a structured file or buffer and then getting the field names that way. However I thought I might...
0
9583
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9423
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10210
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8869
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6668
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5297
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5445
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3955
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3560
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.