APLawrence.com -  Resources for Unix and Linux Systems, Bloggers and the self-employed

© 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) https://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:

<FONT SIZE=+2><B>Select State<BR>Where Desired Station is Located</FONT></FONT><BR>
<SELECT NAME="state" SIZE=5>

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


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

<input type="hidden" name="state" value="+state+">
<FONT SIZE=+2><B>State: MA<BR><P>Select Desired Station</FONT></FONT></FONT><BR><P>

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:


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.

<font SIZE=+2><b>Select Desired YearMonth for<br><font COLOR="CC3300">Coop ID 190120</font></b><br></font>
<option VALUE="190120200312AMHERST" SELECTED>200312 (190120, AMHERST)
<option VALUE="190120200207AMHERST">200207 (190120, AMHERST)
<input type=hidden name="coopid" value="190120">
<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">


So, our final url is going to be:


and we could do something as simple as

 lynx -dump -nolist "https://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,


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.

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:



Unix/Linux Consultants

Skills Tests

Unix/Linux Book Reviews

My Unix/Linux Troubleshooting Book

This site runs on Linode