170 lines
7.1 KiB
Plaintext
170 lines
7.1 KiB
Plaintext
|
From: gherman at my-dejanews.com (Dinu C. Gherman)
|
||
|
Date: Thu, 22 Apr 1999 11:52:33 GMT
|
||
|
Subject: Project for newbie
|
||
|
References: <70alf7.qc6.ln@loopback>
|
||
|
Message-ID: <7fn2i0$7ql$1@nnrp1.dejanews.com>
|
||
|
Content-Length: 7024
|
||
|
X-UID: 114
|
||
|
|
||
|
|
||
|
In article <70alf7.qc6.ln at loopback>, morph at softhome.net wrote:
|
||
|
>
|
||
|
> I've read my way through the tutorial, and am now stuck - where do I go
|
||
|
> from here? I want to learn how to use Python, but don't have any
|
||
|
> pressing projects at the moment - can anyone suggest a program I should
|
||
|
> have a go at writing, to help me learn the language further?
|
||
|
|
||
|
|
||
|
What about this little problem, assuming you're
|
||
|
interested in internet programming and keen to get
|
||
|
familiar with the Python XML module...? ;-)
|
||
|
|
||
|
Have fun,
|
||
|
|
||
|
Dinu
|
||
|
|
||
|
|
||
|
|
||
|
Context:
|
||
|
|
||
|
The Altavista babelfish returns the following result
|
||
|
page (see appendix below) after issuing this request:
|
||
|
|
||
|
"translate 'water' from English to French"
|
||
|
|
||
|
on that WWW page:
|
||
|
|
||
|
http://babelfish.altavista.com
|
||
|
|
||
|
Some quick testing reveales that you can do the same
|
||
|
with just typing the following (wrapped) URL in your
|
||
|
browser:
|
||
|
|
||
|
http://babelfish.altavista.com/cgi-bin/translate?
|
||
|
doit=done&urltext=water&lp=en_fr
|
||
|
|
||
|
Exercise 1:
|
||
|
|
||
|
Write a program babelfish.py calling the Altavista
|
||
|
Babelfish over the WWW (using httplib, say) and parse
|
||
|
its HTML output using your favorite HTML/XML parser
|
||
|
(suggestion: use the XML module written by the Python
|
||
|
XML-SIG) in order to extract the result and print it
|
||
|
nicely in a terminal window like this:
|
||
|
|
||
|
darwin> python babelfish.py water en_fr
|
||
|
l'eau
|
||
|
darwin>
|
||
|
|
||
|
Exercise 2:
|
||
|
|
||
|
Improve your program by allowing multiple words to
|
||
|
be translated in a row, like this (you'll have to
|
||
|
send multiple requests as Babelfish will try to
|
||
|
treat your words as a sentence):
|
||
|
|
||
|
darwin> python babelfish.py spam eggs en_fr
|
||
|
spam
|
||
|
oeufs
|
||
|
darwin>
|
||
|
|
||
|
Appendix: Sample Babelfish output
|
||
|
(see context description)
|
||
|
|
||
|
<html> <head><title>AltaVista: Translations</title> </head> <body
|
||
|
bgcolor=#ffffff text=#000000 link=#003399 vlink=#663366 alink=#ff0000> <MAP
|
||
|
NAME=header> <AREA SHAPE=RECT COORDS="144,0,323,32"
|
||
|
HREF="http://babelfish.altavista.com/cgi-bin/translate?" ALT="AltaVista
|
||
|
Maps"> <AREA SHAPE=RECT COORDS="0,0,128,32"
|
||
|
HREF="http://www.altavista.com/cgi-bin/query" alt="AltaVista Home"> </MAP>
|
||
|
<center><table width=600 border=0 cellspacing=0 cellpadding=0> <tr><td> <img
|
||
|
src=/gifs/new.babelfish_head.gif border=0 NAME="AltaVista Translation"
|
||
|
WIDTH=383 HEIGHT=32 USEMAP=#header ALT="AltaVista Translation"></td><td
|
||
|
align=right valign=bottom> <font face=arial,helvetica size=-1> <a
|
||
|
href="/content/help.htm">Help</a> - <a
|
||
|
href=http://www.altavista.com/cgi-bin/query>AltaVista Home</a></font>
|
||
|
</td></tr> <tr><td colspan=2 BGCOLOR=#003399><img
|
||
|
src=http://www.altavista.com/av/gifs/pixel.gif border=0 width=0
|
||
|
height=2></td></tr> </table> <table border=0 width=600 cellspacing=0
|
||
|
cellpadding=2><tr><td><table width=100% bgcolor=#ffffff cellpadding=5
|
||
|
cellspacing=0 border=0> <tr><td align=center valign=center><ilayer id=ad1
|
||
|
visibility=hidden height=83></ilayer> <nolayer><iframe
|
||
|
src="http://ad.doubleclick.net/adi/babelfish.altavista.digital.com/"
|
||
|
width=500 height=83 marginwidth=0 marginheight=0 hspace=0 vspace=0
|
||
|
frameborder=0 scrolling=no bordercolor="#000000"><A
|
||
|
href="http://ad.doubleclick.net/jump/babelfish.altavista.digital.com/"
|
||
|
alt="Click Here"><img
|
||
|
src="http://ad.doubleclick.net/ad/babelfish.altavista.digital.com/" width=468
|
||
|
height=60 border=0 ismap><br><font size=-1 face=Arial,Helvetica><b>Click
|
||
|
Here</b></font></a></iframe></nolayer></td></tr></table></td></tr></table>
|
||
|
|
||
|
<table border=0 cellspacing=0 cellpadding=0 width=600 BGCOLOR=#FFCC66>
|
||
|
<TR><td width=2><br></td><td><table border=0 cellspacing=0 cellpadding=4
|
||
|
width=596 BGCOLOR=WHITE>
|
||
|
<tr><td colspan=2 align=left BGCOLOR=#FFCC66><b>
|
||
|
|
||
|
<font face="arial, helvetica">En Fran?ais:</b></font>
|
||
|
</td></tr>
|
||
|
<tr><td><img border=0 src="/gifs/clear.gif" width="15" height="0"></td>
|
||
|
<td align="left"><br>
|
||
|
|
||
|
<font face="arial, helvetica">l'eau
|
||
|
<br><br></font></td></tr>
|
||
|
<tr><td align=right colspan=2>
|
||
|
<font face="arial, helvetica" size=-1><a
|
||
|
href="http://altavista.digital.com/cgi-bin/query?q=l%27eau&kl=fr">
|
||
|
<font size=-1>Use the above text to search the
|
||
|
Web</font></a></font></td></tr></table></td><td
|
||
|
width=2><br></td></tr></table><table border=0 cellpadding=0 cellspacing=0
|
||
|
width=600 bgcolor=#ffcc66><tr><td align=center><table border=0 cellpadding=4
|
||
|
cellspacing=0 width="100" bgcolor=#ffcc66><form action="/cgi-bin/translate?"
|
||
|
method="POST">
|
||
|
<input type="hidden" name="doit" value="done">
|
||
|
|
||
|
<tr><td align=left valign=bottom><font size="-1" face="arial,
|
||
|
helvetica"><b>To translate, type <a href="/content/help.htm#trans_text">plain
|
||
|
text</a> or the <a href="/content/help.htm#trans_web">address (URL)</a> of a
|
||
|
Web page here:</b></font></td></tr> <tr><td align=left><textarea rows="6"
|
||
|
wrap=virtual cols="56" name="urltext">water</textarea></td></tr> <tr><td
|
||
|
align=left valign=top> <font size="-1" face="arial, helvetica"><B>Translate
|
||
|
from: <select name="lp"> <option value="en_fr" SELECTED>English to
|
||
|
French</option> <option value="en_de" >English to German</option> <option
|
||
|
value="en_it" >English to Italian</option> <option value="en_pt" >English
|
||
|
to Portuguese</option> <option value="en_es" >English to Spanish</option>
|
||
|
<option value="fr_en" >French to English</option> <option value="de_en"
|
||
|
>German to English</option> <option value="it_en" >Italian to
|
||
|
English</option> <option value="es_en" >Spanish to English</option> <option
|
||
|
value="pt_en" >Portuguese to English</option> </select> <input type="Submit"
|
||
|
value="Translate"></b></font> </td></tr></form></table> </td></tr></table>
|
||
|
<table width=600 cellpadding=0 cellspacing=0 border=0> <tr
|
||
|
bgcolor="#ffcc66"><td align=center><font size=-1 face="arial,helvetica"><br>
|
||
|
Put the power of Babel Fish into IE 5. <b><a
|
||
|
href="http://www.altavista.com/av/avie5/avtools.html">Get AV Power Tools<b>
|
||
|
(119k)</a><p> <b><a href="http://www.systransoft.com/personal.html">Download
|
||
|
SYSTRAN Personal</a> and translate your private documents in
|
||
|
seconds.</font></b><br><br></td></tr> <tr><td bgcolor=#003399 width=100%><img
|
||
|
src="http://altavista.com/av/gifs/pixel.gif" border=0 width=0
|
||
|
height=2></td></tr> </table> <table width=600 border=0 cellspacing=0
|
||
|
cellpadding=4> <tr><td width=440 align=left><font size=-2
|
||
|
face="arial,helvetica"> <a
|
||
|
href="http://altavista.com/cgi-bin/query">AltaVista Home</a> | <a
|
||
|
href="/content/help.htm">Help</a> | <a
|
||
|
href="/content/feedback.htm">Feedback</a> <BR> ©1995-98 | <a
|
||
|
href="http://altavista.com/av/content/disclaimer.htm">Disclaimer</a> | <a
|
||
|
href="http://altavista.com/av/content/privacy.htm">Privacy</a> | <a
|
||
|
href="http://jump.altavista.com/DoubleClick">Advertising Info</a></font></td>
|
||
|
<td valign=middle align=right width=160> <a
|
||
|
href="http://www.systransoft.com/"><IMG SRC="/gifs/systran_big_logo.gif"
|
||
|
WIDTH="138" HEIGHT="39" BORDER="0"></a> </td></tr></table> </center> <layer
|
||
|
src="http://ad.doubleclick.net/adl/babelfish.altavista.digital.com/"
|
||
|
visibility=hidden id=a1 width=590
|
||
|
onload="moveToAbsolute(ad1.pageX,ad1.pageY);
|
||
|
a1.clip.height=83;visibility='show';"></layer> </BODY></HTML>
|
||
|
|
||
|
-----------== Posted via Deja News, The Discussion Network ==----------
|
||
|
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
|
||
|
|
||
|
|
||
|
|
||
|
|