0

XML::RSS::ParserXML ファイルからいくつかの情報を引き出すために使用するこの短い Perl スクリプトがあります。

#!/usr/bin/perl -w
use strict;

use XML::RSS::Parser;
use FileHandle;
use Data::Dumper;
use URI;

my $p = XML::RSS::Parser->new;
my $fh = FileHandle->new('ronicky-doone-by-max-brand.xml');

my $feed = $p->parse_file( $fh );
print $p->errstr;

my $feed_title = $feed->query('/channel/title');
print $feed_title->text_content;

my $feed_desc = $feed->query('/channel/description');
print $feed_desc->text_content;

メソッドがあることは知ってparse_uriいますが、URL をhttp://librivox.org/bookfeeds/ronicky-doone-by-max-brand.xmlURI に変換してパラメーターを渡すことができないようですXML::RSS::Parser::parse_uri

4

1 に答える 1

3

何を試したのかわかりませんが、非常に簡単です。おそらくあなたをFileHandle混乱させたのですか?

このバージョンのコードは正常に動作します。コマンドライン オプションは、短いコマンドライン Perl プログラムを除いて、-w何年も前に に置き換えられたことに注意してください。use warningsまたSTDOUT、この RSS フィードには拡張文字が含まれているため、UTF-8 を期待するように設定する必要がありました。

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)  
于 2013-06-16T03:35:47.437 に答える