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

detect_encoding.pl « examples - github.com/lexborisov/perl-html-myhtml.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: a91e5970c228dcdba5c70f6c3251088fdd6e44d7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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_children($tree, *STDOUT, 0);


$tree->destroy();