web scraping - Perl Scrappy select using class attribute -
i trying scrape using perl scrappy
. select html elements class attribute using 'select'.
<p> <h1> <a href='http://test.com'>test</a> <a href='http://list.com'>list</a> </h1> </p> <p class='parent-1'> <h1> <a class='child-1' href="http://sample.com">samplelink</a> <a class='child-2' href="http://list.com">list</a> </h1> </p>
i need element('a' tag) class name 'child-1' child nod of <p class='parent-1'>
using select method.
i have tried this
#!/usr/bin/perl use scrappy; $scraper = scrappy->new; $scraper->get($url); $scraper->select('p a')->data;
but select first 'p' tag also.
could please me this?
bearing in mind choroba's warning, select <a>
element class of child-1
child of <p>
element class of parent-1
write
$scraper->select('p.parent-1 > a.child-1')
Comments
Post a Comment