Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re^2: How to determine HTML encoding

by slugger415 (Monk)
on Jun 30, 2010 at 18:23 UTC ( [id://847372]=note: print w/replies, xml ) Need Help??


in reply to Re: How to determine HTML encoding
in thread How to determine HTML encoding

Ok I'm going to be dumb here, but I'm not getting HTTP::Response to work.

my $r = HTTP::Response->new($url); print "r: ", $r->decoded_content, "\n";

... returns nothing. What am I doing wrong?
Scott

Replies are listed 'Best First'.
Re^3: How to determine HTML encoding
by Corion (Patriarch) on Jun 30, 2010 at 18:45 UTC

    You're creating a HTTP::Response out of thin air. It does not run off to the server and fetches $url. Maybe you want to actually fetch content through LWP::UserAgent or WWW::Mechanize and then use the ->decoded_content method on whatever response they give you?

      Yes I see, thank you. Scott

      Ok, so I've got some HTML content with my own subroutine:

      my $html = get_content($url);
      print $html;
      

      Result is I get the contents of $html printed, fine.

      Then I want to decode it:

      print HTTP::Response->decoded_content($html);
      

      Result:

      Odd number of elements in hash assignment at C:/Perl/lib/HTTP/Message.pm line 28
      9.
      Use of uninitialized value in print at myscript.pl line 269.
      

      What's going on? I read the doc on decoded_content and messages and it says something about options I don't understand.

      $mess->decoded_content( %options )
      

      Scott

        How do you expect to contruct an HTTP response from just the body of the response? You need the headers too. By creating an H::R response object, you don't magically get the headers your function previously discarded.

        I mentioned that an HTTP response is a possible source of the encoding. I used an example where the HTTP response is provided via an HTTP::Reponse object. The H::R object reflects the HTTP response; it's not a decoding tool.

        You're not starting from an HTTP response. You're starting from an HTML file. I told how to handle that situation too.

        Either fix your function to return an HTTP response and not just the body of an HTTP response, or treat the value returned as a file.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://847372]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (5)
As of 2024-03-19 08:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found