HTML-Miner
NAME
HTML::Miner - This Module 'Mines' (hopefully) useful information for an URL or HTML snippet.
VERSION
Version 1.03
SYNOPSIS
HTML::Miner 'Mines' (hopefully) useful information for an URL or HTML snippet. The following is a list of HTML elements that can be extracted:
Find all links and for each link extract:
URL Title
URL href
URL Anchor Text
URL Domain
URL Protocol
URL URI
URL Absolute location
Find all images and for each image extract:
IMG Source URL
IMG Absolute Source URL
IMG Source Domain
Extracts Meta Elements such as
Page Title
Page Description
Page Keywords
Page RSS Feeds
Finds the final destination URL of a potentially redirecting URL.
Find all JS and CSS files used within the HTML and find their absolute URL if required.
Example ( Object Oriented Usage )
use HTML::Miner;
my $html = "some html";
# or $html = do{local $/;}; with __DATA__ provided
my $html_miner = HTML::Miner->new (
CURRENT_URL => 'www.perl.org' ,
CURRENT_URL_HTML => $html
);
my $meta_data = $html_miner->get_meta_elements() ;
my $links = $html_miner->get_links() ;
my $images = $html_miner->get_images() ;
my ( $clear_url, $protocol, $domain, $uri ) = $html_miner->break_url();
my $css_and_js = $html_miner->get_page_css_and_js() ;
my $out = HTML::Miner::get_redirect_destination( "redirectingurl_here.html" ) ;
my $out = HTML::Miner::get_absolute_url( "www.perl.com/help/faq/", "../../about/" );
Example ( Direct access of Methods )
use HTML::Miner;
my $html = "some html";
# or $html = do{local $/;}; with __DATA__ provided
my $url = "http://www.perl.org";;
my $meta_data = HTML::Miner::get_meta_elements( $url, $html ) ;
my $links = HTML::Miner::get_links( $url, $html ) ;
my $images = HTML::Miner::get_images( $url, $html ) ;
my ( $clear_url, $protocol, $domain, $uri ) = HTML::Minerbreak_url( $url );
my $css_and_js = get_page_css_and_js(
URL => $url ,
HTML => $optionally_html_of_url ,
CONVERT_URLS_TO_ABS => 0/1 , [ Optional argument, default is 1 ]
);
my $out = HTML::Miner::get_redirect_destination( "redirectingurl_here.html" ) ;
my $out = HTML::Miner::get_absolute_url( "www.perl.com/help/faq/", "../../about/" );
Test Data
__DATA__
SiteTitleLink1Link2Link3
Example Output:
my $meta_data = $html_miner->get_meta_elements() ;
# $meta_data->{ TITLE } => "SiteTitle"
# $meta_data->{ DESC } => "desc of site"
# $meta_data->{ KEYWORDS }->[0] => "kw1"
# $meta_data->{ RSS }->[0]->{TYPE} => "application/atom+xml"
my $links = $html_miner->get_links();
# $links->[0]->{ DOMAIN } => "linkone.com"
# $links->[0]->{ ANCHOR } => "Link1"
# $links->[2]->{ ABS_URL } => "http://my_domain_to_mine.com/link3";
# $links->[1]->{ DOMAIN_IS_BASE } => 1
# $links->[1]->{ TITLE } => "title2"
my $images = $html_miner->get_images();
# $images->[0]->{ IMG_LOC } => "http://my_domain_to_mine.com/logo_plain.jpg";
# $images->[2]->{ ALT } => "link3"
# $images->[0]->{ IMG_DOMAIN } => "my_domain_to_mine.com"
# $images->[3]->{ ABS_LOC } => "http://my_domain_to_mine.com/image3.jpg";
my $css_and_js = $html_miner->get_page_css_and_js(
CONVERT_URLS_TO_ABS => 0
);
# $css_and_js will contain:
# {
# CSS => [
# "http://static.mycssdomain.com/frameworks/style/main.css";,
# "/rel_cssfile.css",
# ],
# JS => [
# "http://static.myjsdomain.com/frameworks/barlesque.js";,
# "http://js.revsci.net/gateway/gw.js?csid=J08781";,
# "/about/rel_jsfile.js",
# ],
# }
my $css_and_js = $html_miner->get_page_css_and_js(
CONVERT_URLS_TO_ABS => 1
);
# $css_and_js will contain:
# {
# CSS => [
# "http://static.mycssdomain.com/frameworks/style/main.css";,
# "http://www.perl.org/rel_cssfile.css";,
# ],
# JS => [
# "http://static.myjsdomain.com/frameworks/barlesque.js";,
# "http://js.revsci.net/gateway/gw.js?csid=J08781";,
# "http://www.perl.org/about/rel_jsfile.js";,
# ],
# }
my ( $clear_url, $protocol, $domain, $uri ) = $html_miner->break_url();
# $clear_url => "http://my_domain_to_mine.com/my_page_to_mine.pl";
# $protocol => "http"
# $domain => "my_domain_to_mine.com"
# $uri => "/my_page_to_mine.pl"
HTML::Miner::get_redirect_destination( "redirectingurl_here.html" ) => 'redirected_to'
my $out = HTML::Miner::get_absolute_url( "www.perl.com/help/faq/", "../../about/" );
# $out => "http://www.perl.com/about/";
$out = HTML::Miner::get_absolute_url( "www.perl.com/help/faq/index.html", "index2.html" );
# $out => "http://www.perl.com/help/faq/index2.html";
$out = HTML::Miner::get_absolute_url( "www.perl.com/help/faq/", "../../index.html" );
# $out => "http://www.perl.com/index.html";
$out = HTML::Miner::get_absolute_url( "www.perl.com/help/faq/", "/about/" );
# $out => "http://www.perl.com/about/";
$out = HTML::Miner::get_absolute_url( "www.perl.comhelp/faq/", "http://othersite.com"; );
# $out => "http://othersite.com/";
EXPORT
This Module does not export anything through @EXPORT, however does export all externally available functions through @EXPORT_OK
INSTALLATION
To install this module, run the following commands:
perl Makefile.PL
make
make test
make install
SUPPORT AND DOCUMENTATION
After installing, you can find documentation for this module with the
perldoc command.
perldoc HTML::Miner
You can also look for information at:
RT, CPAN's request tracker
http://rt.cpan.org/NoAuth/Bugs.html?Dist=HTML-Miner
AnnoCPAN, Annotated CPAN documentation
http://annocpan.org/dist/HTML-Miner
CPAN Ratings
http://cpanratings.perl.org/d/HTML-Miner
Search CPAN
http://search.cpan.org/dist/HTML-Miner/
LICENSE AND COPYRIGHT
Copyright (C) 2009 Harish Madabushi, all rights reserved.
This program is free software; you can redistribute it and/or modify it under the terms of the the Artistic License (2.0). You may obtain a copy of the full license at:
http://www.perlfoundation.org/artistic_license_2_0
Any use, modification, and distribution of the Standard or Modified Versions is governed by this Artistic License. By using, modifying or distributing the Package, you accept this license. Do not use, modify, or distribute the Package, if you do not accept this license.
If your Modified Version has been derived from a Modified Version made by someone other than you, you are nevertheless required to ensure that your Modified Version complies with the requirements of this license.
This license does not grant you the right to use any trademark, service mark, tradename, or logo of the Copyright Holder.
This license includes the non-exclusive, worldwide, free-of-charge patent license to make, have made, use, offer to sell, sell, import and otherwise transfer the Package with respect to any patent claims licensable by the Copyright Holder that are necessarily infringed by the Package. If you institute patent litigation (including a cross-claim or counterclaim) against any party alleging that the Package constitutes direct or contributory patent infringement, then this Artistic License to you shall terminate on the date that such litigation is filed.
Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.