in reply to How can i have the titles and the prices?
If the page is simple enough, an approach that makes the HTML parser a bit less daunting would be to use an approach based on CSS selectors. There are several modules that implement this approach, like Mojo::DOM, Web::Magic, Web::Query. Some others like Web::Scraper provide a bit more scaffolding around running data extraction.
App::scrape is a minimalistic scraper that implements the two steps of 1) fetching an HTML page and 2) extracting data according to CSS selectors. The basic invocation would be like the following (assuming your data lives in a file 1054800.html:
C:\>scrape file:///1054800.html .product-name .price Please help $20.00
So, armed with the two selectors, you can then turn from the command line tool to using the selectors with (for example) App::scrape:
#!perl -w use strict; use App::scrape 'scrape'; use LWP::Simple 'get'; use Data::Dumper; my $html= get 'file:///1054800.html'; my @info = scrape( $html, { product => '.product-name', price => '.price', }, ); print Dumper \@info; __END__ C:\>perl -w tmp.pl $VAR1 = [ { 'product' => 'Please help', 'price' => '$20.00' } ];
Note that App::scrape assumes that your data is basically tabular. It does not cope well with data with a more complex structure, and especially not well with the situation that one product maybe has no price tag.
|
|---|