Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/lexborisov/perl-html-myhtml.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlex <lexinhell@gmail.com>2016-02-28 20:06:04 +0300
committerlex <lexinhell@gmail.com>2016-02-28 20:06:04 +0300
commit62a42a38a6c3b8e6d58dfee4c602118ba64290e6 (patch)
tree2ece412d2f258ce188a4e3906fe7eaaac5374c4c /examples
First commit
Diffstat (limited to 'examples')
-rw-r--r--examples/detect_encoding.pl35
1 files changed, 35 insertions, 0 deletions
diff --git a/examples/detect_encoding.pl b/examples/detect_encoding.pl
new file mode 100644
index 0000000..cea8102
--- /dev/null
+++ b/examples/detect_encoding.pl
@@ -0,0 +1,35 @@
+#!/usr/bin/perl -w
+
+use utf8;
+use strict;
+
+use HTML::MyHTML;
+use LWP::UserAgent;
+
+my $ua = LWP::UserAgent->new;
+my $req = HTTP::Request->new(GET => "https://www.google.com/");
+my $res = $ua->request($req);
+
+my $body = $res->content;
+
+# init
+my $myhtml = HTML::MyHTML->new(MyHTML_OPTIONS_DEFAULT, 1);
+my $tree = $myhtml->new_tree();
+
+# detect encoding
+my $encoding;
+$myhtml->encoding_detect($body, $encoding);
+
+# parse
+$myhtml->parse($tree, $encoding, $body);
+
+# print result
+print "Print HTML Tree:\n";
+$tree->document->print_childs($tree, *STDOUT, 0);
+
+
+$tree->destroy();
+
+
+
+