zzspectrez has asked for the wisdom of the Perl Monks concerning the following question:
I am currently trying to learn spanish. I found a website that has a page that displays a new spanish word each day.
I would like to write a script that I can have cron run that will download the web page, parse the spanish word for the day and email mail it to me so that I can download it to my palm pilot.
Not a difficult task I know. The only part Im not to sure about is if Im parsing the data properly. Im am inexperienced with regular expressions, so would like fellow monks suggestions.
An example of the html src:
.... SNIP ..... if (day == 22) document.write("<p><font size='+2'><font color='#cc0000 +'><i><b>acongojar:</b></i></font> to sadden or grieve. <i>Mi hermano +estaba muy acongojado cuando murió\; su esposa</i>, my brother +was very sad when his wife died.</font>"); if (day == 23) document.write("<p><font size='+2'><font color='#cc0000 +'><i><b>contestar:</b></i></font> to answer. <i>Sus oraciones fueron +contestadas</i>, her prayers were answered.</font>"); .... SNIP ....
I have written a quick script to download and print out the data but am unsure if I should do things differently. It appears to work.
Test perl script
#!/usr/bin/perl -Tw use strict; use LWP::Simple; my $url = 'http://spanish.about.com/homework/spanish/blword.htm'; die "Unable to download Spanish word of the day." unless (defined(my $ +web = get ($url))); my $today = ((localtime)[3]); print "\nToday: $today\n"; my ($word, $def, $sent, $trans) = $web =~ m[if \(day == $today\).+?<b> +(\w+):</b></i></font>(.+?)<i>(.+?)</i>,(.+?).</font>]s; print "Word: $word\nDefinition: $def\nSentence: $sent\nTranslation: $t +rans\n";
Thanks for any suggestions!
zzSPECTREz
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Pattern matching html.
by davorg (Chancellor) on Nov 24, 2000 at 01:23 UTC | |
by zzspectrez (Hermit) on Nov 25, 2000 at 05:45 UTC | |
Re: Patern matching html.
by rpc (Monk) on Nov 24, 2000 at 01:35 UTC | |
by zzspectrez (Hermit) on Nov 25, 2000 at 05:59 UTC | |
by rpc (Monk) on Nov 26, 2000 at 02:19 UTC | |
Re: Patern matching html.
by Anonymous Monk on Nov 24, 2000 at 00:29 UTC |