[26355] in Perl-Users-Digest
Perl-Users Digest, Issue: 8528 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Oct 16 14:05:45 2005
Date: Sun, 16 Oct 2005 11:05:06 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Sun, 16 Oct 2005 Volume: 10 Number: 8528
Today's topics:
HTML::TokeParser <dvh@dvhdvhdvhdvdh.dvh>
Re: HTML::TokeParser <steve@uptime.org.uk>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sun, 16 Oct 2005 17:07:19 +0000 (UTC)
From: "DVH" <dvh@dvhdvhdvhdvdh.dvh>
Subject: HTML::TokeParser
Message-Id: <diu1c6$msj$1@nwrdmz01.dmz.ncs.ea.ibs-infra.bt.com>
Hi,
I'm trying to get tokeparser to fetch a series of hyperlinks and print the
URL followed by the link text.
The following script ("eurofeed.pl") gives me "Can't coerce array into hash
at eurofeed.pl line 31"
Line 31 is "if ($tag->[2]{class} and $tag->[2]{class} eq 'docSel-titleLink')
{"
The HTML looks like this:
=======================================
<td colspan="2"> </td>
<td align="left" colspan="3">
<a title="" class="docSel-titleLink"
href="pressReleasesAction.do?reference=EPSO/05/06">
My link text here
</a>
</td>
</tr>
---------------------------------------------
My script looks like this:
#!/usr/bin/perl -w
use strict;
use LWP::Simple;
use HTML::TokeParser;
use XML::RSS;
my $content =
et( "http://europa.eu.int/rapid/recentPressReleasesAction.do?guiLanguage=en&
hits=500" ) or die $!;
my $stream = HTML::TokeParser->new( \$content ) or die $!;
my ($tag, $headline, $url);
while ( $tag = $stream->get_tag("a") ) {
if ($tag->[2]{class} and $tag->[2]{class} eq 'docSel-titleLink') {
$url = $tag->[2]{href} || "--";
$headline = $stream->get_trimmed_text('/a')
print $url
print $headline
-----------------------------------------------------------
I think the problem lies in the ordering of tags, but that's as far as I've
got with working out what's wrong.
------------------------------
Date: Sun, 16 Oct 2005 18:35:54 +0100
From: Stephen Hildrey <steve@uptime.org.uk>
Subject: Re: HTML::TokeParser
Message-Id: <1129484153.30203.0@doris.uk.clara.net>
DVH wrote:
> I'm trying to get tokeparser to fetch a series of hyperlinks and print the
> URL followed by the link text.
>
> The following script ("eurofeed.pl") gives me "Can't coerce array into hash
> at eurofeed.pl line 31"
>
> Line 31 is "if ($tag->[2]{class} and $tag->[2]{class} eq 'docSel-titleLink')
You probably want ->[1] rather than ->[2]
Regards,
Steve
--
Stephen Hildrey
E-mail: steve@uptime.org.uk / Tel: +442071931337
Jabber: steve@jabber.earth.li / MSN: foo@hotmail.co.uk
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>
Administrivia:
#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc. For subscription or unsubscription requests, send
#the single line:
#
# subscribe perl-users
#or:
# unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.
NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.
#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V10 Issue 8528
***************************************