Commit dde575a1 authored by Birte Kristina Friesel's avatar Birte Kristina Friesel
Browse files

Use HTML::TreeBuilder::LibXML. Major performance enhancement.

parent 8413c8a4
Loading
Loading
Loading
Loading
+11 −8
Original line number Diff line number Diff line
@@ -7,7 +7,7 @@ use warnings;
use 5.010;

use Getopt::Long qw/:config no_ignore_case/;
use HTML::TreeBuilder::XPath;
use HTML::TreeBuilder::LibXML;
use WWW::Mechanize;

my $firsturl = 'http://efa.vrr.de/vrr/XSLT_TRIP_REQUEST2?language=de&itdLPxx_transpCompany=vrr';
@@ -37,8 +37,9 @@ sub check_ambiguous {
			"Ambiguous input for %s\n",
			$select->attr('name'),
		);
		foreach my $val ($select->findnodes_as_strings('./option')) {
			say "\t$val";
		foreach my $val ($select->findnodes('./option')) {
			print "\t";
			say $val->as_trimmed_text();
		}
	}
	if ($ambiguous) {
@@ -209,7 +210,7 @@ sub parse_tree {
		}

		if ($colspan == 8) {
			if ($td->as_text() =~ / (?<no> \d+ ) \. .+ Fahrt /x) {
			if ($td->as_trimmed_text() =~ / (?<no> \d+ ) \. .+ Fahrt /x) {
				$con_no = $+{'no'} - 1;
				$con_part = 0;
				next;
@@ -225,8 +226,8 @@ sub parse_tree {
			}
		}

		if (not $td->exists('./img') and $td->as_text() !~ /^\s*$/) {
			push(@{$cons->[$con_no]->[$con_part]}, $td->as_text());
		if (not @{$td->findnodes('./img')} and $td->as_text() !~ /^\s*$/) {
			push(@{$cons->[$con_no]->[$con_part]}, $td->as_trimmed_text());
		}
	}
	return $cons;
@@ -325,7 +326,9 @@ if ($test_dump) {
	exit 0
}

my $tree = HTML::TreeBuilder::XPath->new_from_content($content);
my $tree = HTML::TreeBuilder::LibXML->new();
$tree->parse($content);
$tree->eof();

check_ambiguous($tree);

+7 −7

File changed.

Contains only whitespace changes.