我不知道您尝试过什么,但它非常简单。也许使用FileHandle
混淆了你?
这个版本的代码工作正常。请注意,-w
命令行选项在多年前已被替换为use warnings
,除了简短的命令行 Perl 程序。此外,我不得不设置STDOUT
期待 UTF-8,因为此 RSS 提要中有一些扩展字符。
use strict;
use warnings;
use XML::RSS::Parser;
binmode STDOUT, ':encoding(UTF-8)';
my $parser = XML::RSS::Parser->new;
my $feed = $parser->parse_uri('http://librivox.org/bookfeeds/ronicky-doone-by-max-brand.xml');
printf "Title: %s\n", $feed->query('/channel/title')->text_content;
printf "Description: %s\n", $feed->query('/channel/description')->text_content;
输出
Title: Librivox: Ronicky Doone by Brand, Max
Description: Frederick Schiller Faust (1892-1944), is best known today for his western fiction. Faust was born in Seattle, Washington and at an early age moved with his parents to the San Joaquin Valley in California where he worked as a ranchhand. After a failed attempt to enlist in the Great War in 1917 and with the help of Mark Twain's sister he met Robert Hobart Davis, editor of All-Story Weekly and became a regular contributor writting under his most used pseudonym “Max Brandâ€. He wrote in many genres during his career and produced more than 300 western novels and stories. His most famous characters were Destry and Dr. Kildare, both of which were produced in film. Faust was killed in Italy in 1944 as a front line war correspondent at the age of 51. He is buried in the Sicily-Rome American Cemetery in Nettuno, Italy.
Ronicky Doone (1926) is a hero of the west, respected by the law-abiding citizen and hated by bushwhacking bandits. Bill Gregg is a man in love, not about to be deflected from meeting his lady love for the first time, and willing to stand up to the living legend to reach her. This initial meeting leads to a friendship between the two and they travel east to New York City on the trail of the girl. When they find the girl, Caroline Smith, and she refuses to leave, Ronicky must discover the secret that holds her. They encounter the sinister John Mark and the beautiful Ruth Tolliver and are exposed to the horrors and vices of big city life as they attempt to rescue Caroline and find their way back to the mountain-desert of the west. (Summary by Rowdy Delaney)