joyfedl has asked for the wisdom of the Perl Monks concerning the following question:
I have a problem with my script. i cant output the response very well
this is the error i get
away_teamsARRAY(0x55fbf77894a0)timesARRAY(0x55fbf743be78)home_teamsARRAY(0x55fbf71ab7b0)scoresARRAY(0x55fbf71aba98)
this is the output i expect
times home_teams scores away_teams 12.05. 17:00 Brighton 1 - 4 Manchester City
Full code
#!/usr/bin/perl - wT use strict; use warnings; use LWP::UserAgent; use HTTP::Request; use HTML::TreeBuilder; use Data::Dumper; use CGI::Carp qw(fatalsToBrowser warningsToBrowser); # show errors in +browser print "Content-type: text/html\n\n"; # print output to browser my $url = 'https://www.flashscore.com/football/england/premier-league- +2018-2019/results/'; my $ua = LWP::UserAgent->new; sub get_scores { my $response = $ua->get($url); if ($response->is_success) { my $tree = HTML::TreeBuilder->new; $tree->parse($response->decoded_content); return $tree; } else { die $response->status_line; } } my $results = get_scores(); my @times = map { $_->as_text } $results->look_down(_tag => 'div', cla +ss => 'event__time'); my @home_teams = map { $_->as_text } $results->look_down(_tag => 'div' +, class => 'event__participant event__participant--home'); my @scores = map { $_->as_text } $results->look_down(_tag => 'div', cl +ass => 'event__scores fontBold'); my @away_teams = map { $_->as_text } $results->look_down(_tag => 'div' +, class => 'event__participant event__participant--away'); my %dict_res; for my $ind ($results) { push @{$dict_res{'times'}}, @times[$ind]; push @{$dict_res{'home_teams'}}, @home_teams[$ind]; push @{$dict_res{'scores'}}, @scores[$ind]; push @{$dict_res{'away_teams'}}, @away_teams[$ind]; print %dict_res; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Web scrapping
by 1nickt (Canon) on Jul 11, 2025 at 09:44 UTC | |
|
Re: Web scrapping
by ysth (Canon) on Jul 10, 2025 at 18:03 UTC | |
by soonix (Chancellor) on Jul 11, 2025 at 06:47 UTC | |
by jdporter (Paladin) on Jul 11, 2025 at 12:27 UTC | |
|
Re: Web scraping
by hippo (Archbishop) on Jul 10, 2025 at 22:21 UTC | |
by joyfedl (Acolyte) on Jul 11, 2025 at 15:14 UTC | |
by marto (Cardinal) on Jul 11, 2025 at 18:41 UTC | |
by joyfedl (Acolyte) on Jul 11, 2025 at 19:41 UTC | |
by marto (Cardinal) on Jul 11, 2025 at 19:57 UTC | |
|
Re: Web scrapping
by LanX (Saint) on Jul 10, 2025 at 17:53 UTC | |
by joyfedl (Acolyte) on Jul 10, 2025 at 18:51 UTC | |
by LanX (Saint) on Jul 10, 2025 at 19:50 UTC | |
| A reply falls below the community's threshold of quality. You may see it by logging in. |