[COLUG] use wget to download a password web page
Steven Huwig
shuwig at columbus.rr.com
Mon Dec 4 19:35:37 EST 2006
On Dec 4, 2006, at 2:44 PM, Vincent Herried wrote:
> I'm trying to use wget to access my account with
> the columbus library web page.
>
> Anyone had any success with wget reading
> a password protected web page?
I can't speak for wget, but I have done this with Python. Probably
you just need to encode the right POST parameters with --post-data;
see the calls to urllib.urlencode() and urllib2.urlopen().
from BeautifulSoup import BeautifulSoup
import urllib2, urllib, sys, subprocess
applescript_gibberish = """
tell application "iCal"
tell (the first calendar whose title is "Library Books")
if not ((the first todo whose description = "%s") exists) then
make new todo at end of todos with properties
{description:"%s", due date: date "%s", summary:"Book Due"}
end if
end tell
end tell
"""
def run():
url = "http://webpac.columbuslibrary.org/cgi-bin/wpay1154.shtml"
post_data = urllib.urlencode({"patronid":"1238675309",
"patronpin":"2323"})
input = urllib2.urlopen(url, post_data)
soup = BeautifulSoup(input.read())
rows = soup.find(name="th", text=" Due Date ").findParent
(name="table").findChildren(name="tr")
for row in rows[1:]:
row_data = row.findChildren(name="td")
title = row.findChildren(name="td")[0].string
due_date = row.findChildren(name="td")[2].string
code = applescript_gibberish % (title, title, due_date)
proc = subprocess.Popen("osascript", stdin=subprocess.PIPE)
proc.stdin.write(code)
proc.stdin.close()
if __name__ == '__main__':
run()
More information about the colug432
mailing list