Skip to content

Instantly share code, notes, and snippets.

@chankeypathak
Created January 5, 2015 07:40
Show Gist options
  • Save chankeypathak/deb33525ec32de1a84e3 to your computer and use it in GitHub Desktop.
Save chankeypathak/deb33525ec32de1a84e3 to your computer and use it in GitHub Desktop.
HTML::TreeBuilder::XPath - Searching a string on a URL
#!/usr/bin/perl
use strict;
use LWP::UserAgent;
use HTML::TreeBuilder::XPath;
my $stringsearch = "solutions";
my $url = "http://www.matrixx.com/";
my $ua = LWP::UserAgent->new;
my $response = $ua->get($url);
die "Http error\n" unless $response->is_success;
my $tree = HTML::TreeBuilder::XPath->new_from_content(
$response->decoded_content
);
print "searched string found\n" if $tree->exists(
"//*[contains(name(), '$stringsearch')] | //@*[contains(., '$stringsearch')]"
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment