Question

I'm writing a web scraper, and am a Perl novice. I'm using HTML::TreeBuilder to get the data I need, but I've run into a case I'm not sure how to handle. Here's some sample HTML:

<div class="anything" val="20" name="matchup">someUniqueData</div>

I want to extract the val from this HTML tag. I've been using findvalues() to do most of my work, but I don't know if this can pull data from inside tags. I've glossed over the documentation unsuccessfully. Is there a simple solution for this type of scrape?

Was it helpful?

Solution

You need (using HTML::TreeBuilder::XPath):

my ($val) = $tree->findvalues('//div[@class="anything"]/@val');
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top