# # Understanding Web Forms
APLawrence.com -  Resources for Unix and Linux Systems, Bloggers and the self-employed

I've removed advertising from most of this site and will eventually clean up the few pages where it remains.

While not terribly expensive to maintain, this does cost me something. If I don't get enough donations to cover that expense, I will be shutting the site down in early 2020.

If you found something useful today, please consider a small donation.



Some material is very old and may be incorrect today

© December 2003 Tony Lawrence

Understanding Web Forms

The other day I was asked to help automate getting data from a Government web page: www.ncdc.noaa.gov/servlets/DLYP (link dead, sorry) http://www.ncdc.noaa.gov/servlets/DLYP

If you go to that page, you can drill into a state, select a station near you, and get precipitation data for certain months. That's fine, but my customer wanted to take the human element out of it: to download the data automatically. Writing a Perl script or even a shell script (with "curl" or lynx) isn't hard, but how can we get the right selections?

It's just a script

If you pay careful attention, you'll notice that after you select a state and click "Continue", the address hasn't changed: you are still at www.ncdc.noaa.gov/servlets/DLYP. That means that DYLP is a script, a script that interprets forms. We can confirm that by looking at the source (View Source) and noting this section:

<FORM METHOD=POST ACTION="DLYP">
<FONT SIZE=+2><B>Select State<BR>Where Desired Station is Located</FONT></FONT><BR>
<SELECT NAME="state" SIZE=5>
<OPTION VALUE="AL" SELECTED>Alabama
<OPTION VALUE="AK">Alaska
 

That tells me that to get to the next page, I could do it in one step by using a url like this:

>http://www.ncdc.noaa.gov/servlets/DLYP?state=MA

Now take a look at that page and you'll see something very important:

<FORM METHOD=POST ACTION="DLYP">
<input type="hidden" name="state" value="+state+">
<FONT SIZE=+2><B>State: MA<BR><P>Select Desired Station</FONT></FONT></FONT><BR><P>
<FONT><SELECT NAME="coban" SIZE=5>
<OPTION VALUE="190120" SELECTED>AMHERST 190120
<OPTION VALUE="190190">ASHBURNHAM 190190
<OPTION VALUE="190408">BARRE FALLS DAM 190408
 

Notice that

input type="hidden" name="state" value="+state+
 

The variable that we already passed has been encoded into the new page so that it can be passed on. We continue building our string:

http://www.ncdc.noaa.gov/servlets/DLYP?state=MA&coban=190120

and this brings us directly to a page where we can select the month and type of output we desire. If we look at the source, we see that the programmer has changed things. The "state" and "coban" variables are gone, and have been replaced with a new variable.

<form METHOD=POST ACTION="DLYP" TARGET="_TOP">
<font SIZE=+2><b>Select Desired YearMonth for<br><font COLOR="CC3300">Coop ID 190120</font></b><br></font>
<select NAME="VARVALUE" SIZE=5>
<option VALUE="190120200312AMHERST" SELECTED>200312 (190120, AMHERST)
<option VALUE="190120200207AMHERST">200207 (190120, AMHERST)
</select>
<p>
<input type=hidden name="coopid" value="190120">
<p>
<b>
<font COLOR=CC3300>View</font>
<input TYPE=radio NAME="which" VALUE="DLYPFORM" CHECKED>Web Form 
<input TYPE=radio NAME="which" VALUE="ascii">ASCII
<p><input type=submit VALUE="Continue">

</form></b>
</form>
 

So, our final url is going to be:

http://www.ncdc.noaa.gov/servlets/DLYP?coopid=190120&VARVALUE=190120200312AMHERST&which=ascii

and we could do something as simple as

 lynx -dump -nolist "http://www.ncdc.noaa.gov/servlets/DLYP?coopid=190120&VARVALUE=190120200312AMHERST&which=ascii"
 

to get it. We'd use shell scripting or Perl or whatever to construct the command with the data we want, and probably another script to parse the results, but that's all easy to do.

The "200312" is for December 2003. If you are trying this at some later time, change that part of the url.

Note that if any values had spaces or other special characters, we'd need to encode them. For example,

http://www.ncdc.noaa.gov/servlets/DLYP?coopid=301185&VARVALUE=301185200312CANTON%204%20SE&which=ascii

So, all we need is to get the "coopid" and station name for the places we are interested in, and construct a date string, and we can get whatever we want (assuming they have it, of course) whenever we want from their web form.

If you found something useful today, please consider a small donation.



Got something to add? Send me email.





(OLDER)    <- More Stuff -> (NEWER)    (NEWEST)   

Printer Friendly Version

->
-> Understanding Web Forms


Inexpensive and informative Apple related e-books:

Take Control of Upgrading to El Capitan

Take Control of Numbers

Take Control of Parallels Desktop 12

Take Control of OS X Server

iOS 8: A Take Control Crash Course





More Articles by © Tony Lawrence





Printer Friendly Version

Have you tried Searching this site?

This is a Unix/Linux resource website. It contains technical articles about Unix, Linux and general computing related subjects, opinion, news, help files, how-to's, tutorials and more.

Contact us


Printer Friendly Version





The people I distrust most are those who want to improve our lives but have only one course of action in mind. (Frank Herbert)




Linux posts

Troubleshooting posts


This post tagged:

Basics

Web/HTML



Unix/Linux Consultants

Skills Tests

Unix/Linux Book Reviews

My Unix/Linux Troubleshooting Book

This site runs on Linode