Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

comment on

( [id://3333] : superdoc . print w/replies, xml ) Need Help??
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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.