good day dear monks

i try do a parser job with the use HTML::TreeBuilder::XPath; well i tried to find out the positons with Xpather but this was a bit too heavy. So i decided to do it with a simple example...



use strict; use HTML::TreeBuilder::XPath; my $tree = HTML::TreeBuilder::XPath->new; #use real file name here open(my $fh, "<", "file.html") or die $!; $tree->parse_file($fh); my ($name) = $tree->findnodes(qq{/html/body/table/tr[1]/td[2]}); my ($type) = $tree->findnodes(qq{/html/body/table/tr[1]/td[2]}); my ($adress) = $tree->findnodes(qq{/html/body/table/tr[1]/td[2]}); my ($adress_two) = $tree->findnodes(qq{/html/body/table/tr[1]/td[2]}); my ($telephone) = $tree->findnodes(qq{/html/body/table/tr[1]/td[2]}); my ($fax) = $tree->findnodes(qq{/html/body/table/tr[1]/td[2]}); my ($internet) = $tree->findnodes(qq{/html/body/table/tr[1]/td[2]}); my ($officer) = $tree->findnodes(qq{/html/body/table/tr[1]/td[2]}); my ($employees) = $tree->findnodes(qq{/html/body/table/tr[1]/td[2]}); my ($offices) = $tree->findnodes(qq{/html/body/table/tr[1]/td[2]}); my ($worker) = $tree->findnodes(qq{/html/body/table/tr[1]/td[2]}); my ($country) = $tree->findnodes(qq{/html/body/table/tr[1]/td[2]}); my ($the_council)= $tree->findnodes(qq{/html/body/table/tr[1]/td[2]}); print $name->as_text; print $type->as_text; print $adress->as_text; print $adress_two->as_text; print $telephone->as_text; print $fax->as_text; print $internet->as_text; print $officer->as_text; print $employees->as_text; print $offices->as_text; print $worker->as_text; print $country->as_text; print $the_council->as_text;
is this all right ? See one of the example sites: http://www.kultusportal-bw.de/servlet/PB/menu/1188427/index.html?COMPLETEHREF=http://www.kultus-bw.de/did_abfrage/detail.php?id=04313488


in the grey shadowed block you see the wanted information: 17 lines that are wanted. Note - i have 5000 different HTML-files - that all are structured in the very same way!

That means i would be happy to have a template that can be runned with HTML::TokeParser::Simple and DBI. That would be great!!

love to hear from you

pb1

In reply to Xpather running against a simple HTML-document - testing and evaluation by Perlbeginner1

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.