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
In reply to Patern matching html. by zzspectrez
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |