in reply to Re: Reading an XML page
in thread Reading an XML page
#!/usr/bin/perl -wT use strict; use IO::Socket; use HTML::Entities; require './libraryCommon.pl'; unless (@ARGV) { die "Exiting without parameter. (HINT: You need to p +ass the ISBN)\n"; } unless (testISBN($ARGV[0])) { my $host="xml.amazon.com"; my $port=80; my $buff=""; my $line; my $title=""; my $date=""; my $manufacturer=""; my $author=""; my @author; my $count=0; my $isbn=$ARGV[0]; my $getBook="GET http://$host/onca/xml2?t=webservices-20&dev-t=D3N +1ICFCFE4DHV&AsinSearch=$isbn&type=lite&f=xml HTTP/1.0\ \n\n"; my $sock=new IO::Socket::INET(PeerAddr => $host, PeerPort => $port +, Proto => 'tcp') or die "Couldn't connect to $host"; $sock->autoflush(1); print $sock $getBook; $count=0; while (<$sock>) { decode_entities($_); if (m%<ProductName>(.*?)</ProductName>%) { $title = $1 } elsif (m%<Author>(.*?)</Author>%) { $author[$count]=$1; $count++; } elsif (m%<ReleaseDate>.*, (\d\d\d\d)</ReleaseDate>%) { $date=$ +1; } elsif (m%<Manufacturer>(.*?)<\/Manufacturer>%) { $manufacturer +=$1; } } close($sock); print $title, "\n"; foreach $author (@author) { print $author, "\n" }; print $date, "\n"; print $manufacturer, "\n"; } else { die "Exiting due to the fact that you have supplied an invalid +ISBN."; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Re: Reading an XML page
by BrowserUk (Patriarch) on May 28, 2003 at 05:38 UTC | |
by Guildencrantz (Sexton) on May 28, 2003 at 05:49 UTC |