I am creating a scrapper that gets the url from an index and writes it to a dat file. Then another scrapper that reads the dat in a while loop and scrapes data from it. I have two different version of code one that works and one that doesn't. The one that works, I have defined the content in which to scrape. The one that doesn't work, the content is defined in a variable which is read from the dat file. If anyone can help, it would be much appretiated.
Works:
#!/usr/bin/perl use LWP::Simple; use HTML::TokeParser; use URI::Escape; &sw; sub sw { $content = get('http://example.com/test.html'); ....truncated
Doesn't work:
#!/usr/bin/perl -w use LWP::Simple; use HTML::TokeParser; use URI::Escape; use DBI; use DBD::mysql; $database = "Assets2"; $host = "localhost"; $port = "3306"; $user= "assets"; $password= "xxx"; $dsn = "DBI:mysql:$database:$host:$port"; $connect = DBI->connect($dsn,$user, $password); &get_index; sub get_index { $query1 = "Select * from devices"; $query_handle1 = $connect->prepare($query1); $query_handle1->execute; $query_handle1->bind_columns(\$id,\$device); while ($query_handle1->fetch) { print "id: $id\tname: $device\n"; &switch_properties; } } sub switch_properties { $content = get('http://example.com/$device'); ...truncated
Error:
Use of uninitialized value in substr at /usr/lib/perl5/HTML/PullParser +.pm line 80. Use of uninitialized value in length at /usr/lib/perl5/HTML/PullParser +.pm line 83.
Error with debugger:
Use of uninitialized value in substr at /usr/lib/perl5/HTML/PullParser +.pm line 80. at /usr/lib/perl5/HTML/PullParser.pm line 80 HTML::PullParser::get_token('HTML::TokeParser=HASH(0x9ce9fd0)' +) called at /usr/lib/perl5/HTML/TokeParser.pm line 52 HTML::TokeParser::get_tag('HTML::TokeParser=HASH(0x9ce9fd0)', +'tr') called at switchmapHTMLTEST1.pl line 51 main::switch_properties called at switchmapHTMLTEST1.pl line 2 +8 main::get_index called at switchmapHTMLTEST1.pl line 19 Use of uninitialized value in length at /usr/lib/perl5/HTML/PullParser +.pm line 83. at /usr/lib/perl5/HTML/PullParser.pm line 83 HTML::PullParser::get_token('HTML::TokeParser=HASH(0x9ce9fd0)' +) called at /usr/lib/perl5/HTML/TokeParser.pm line 52 HTML::TokeParser::get_tag('HTML::TokeParser=HASH(0x9ce9fd0)', +'tr') called at switchmapHTMLTEST1.pl line 51 main::switch_properties called at switchmapHTMLTEST1.pl line 2 +8 main::get_index called at switchmapHTMLTEST1.pl line 19

In reply to Scrapper outputing error -w by parkprimus

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.