file won't download.. what am i missing ?
okay, here i am trying to download some realplayer type of files from www.rick.com the file won't download even from regular browser. but it does play thr realplayer when i click the file. it probably the case like other media files that users can't download but can linsten/watch online. but anyway, i am just playing it with LWP. here is my code: #!/usr/bin/perl -w use strict; use HTTP::Request::Common qw(GET POST); use LWP::UserAgent; use HTTP::Cookies; my $accept = ACC; image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/msword, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, */* ACC my $refer_url = 'http://www.rick.com/interviews.html'; my $ra_url = 'http://www.rick.com/audio/interviews/danacarvey073002.ra'; my $ua = LWP::UserAgent-new('keep_alive' = 1); #$ua-cookie_jar(HTTP::Cookies-new(file='mycookie',autosave=1,ignore_discard = 1)); $ua-cookie_jar(HTTP::Cookies-new(file='mycookie',hide_cookie2=1)); $ua-agent('Mozilla/4.0 (compatible; MSIE 6.0; Windws NT 5.1)'); $ua-get($refer_url); # grab cookie from refer page my $req = GET $ra_url; $req-referer($refer_url); $req-header('Accept-Language' = 'en-us'); $req-header('Accept' = $accept); my $resp = $ua-request($req); open F,test.ra; print F $resp-content; close F; the http traffic between them is suppose to be shown as GET /audio/interviews/danacarvey073002.ra HTTP/1.1 Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/msword, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, */* Referer: http://www.rick.com/interviews.html Accept-Language: en-us Accept-Encoding: gzip, deflate User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.0.3705) Host: www.rick.com Connection: Keep-Alive Cookie: popup_single_cookie=16; poll_cookie_123=Should+suicide+during+a+live+concert+be+Televised+%3F HTTP/1.1 200 OK Date: Mon, 13 Oct 2003 06:47:53 GMT Server: Apache/1.3.27 (Unix) PHP/3.0.18 Connection: close Transfer-Encoding: chunked Content-Type: audio/x-pn-realaudio 39 http://www.rick.com/audio/interviews/danacarvey073002.ra 0 using code above i am getting GET /audio/interviews/danacarvey073002.ra HTTP/1.1 TE: deflate,gzip;q=0.3 Keep-Alive: 300 Connection: Keep-Alive, TE Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/msword, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, */* Accept-Language: en-us Host: www.rick.com Referer: http://www.rick.com/interviews.html User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windws NT 5.1) Cookie: popup_single_cookie=16 HTTP/1.1 200 OK Date: Mon, 13 Oct 2003 08:22:38 GMT Server: Apache/1.3.27 (Unix) PHP/3.0.18 Connection: close Transfer-Encoding: chunked Content-Type: audio/x-pn-realaudio 39 http://www.rick.com/audio/interviews/danacarvey073002.ra 0 the content of cookie file being loaded into HTTP::Cookies is #LWP-Cookies-1.0 Set-Cookie3: popup_single_cookie=15; poll_cookie_123=Should+suicide+during+a+live+concert+be+Televised+%3F; path=/; domain=www.rick.com; path_spec; discard; version=0 The originaly content being saved from HTTP::Cookies is #LWP-Cookies-1.0 Set-Cookie3: popup_single_cookie=1; path=/; domain=www.rick.com; path_spec; discard; version=0 note: it missed the poll_cookie_123=Should+suicide+during+a+live+concert+be+Televised+%3F; but although i have the full entry in 'mycookie' file, the traffic is really looks like : GET /audio/interviews/danacarvey073002.ra HTTP/1.1 #some more here Referer: http://www.rick.com/interviews.html User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windws NT 5.1) Cookie: popup_single_cookie=16 where is the poll_cookie_123 part ? another weird things is that the value of popup_single_cookie is 16 as always. but if i have the value setup as 16 in mycookie file, it will be shown in above as 17. so that's why i have 15 instead. okay. just wondering if this ra file can actually be downloaded. regards, Qiang __ Do you Yahoo!? The New Yahoo! Shopping - with improved product search http://shopping.yahoo.com
html tree question. clumsy ?
hi, firstly , thanks for the help from the previous post. i am trying to add html tag into html files while traversing a directory. a simple example is like my $tree = HTML::TreeBuilder-new; my $literal = HTML::Element-new('~literal','text' = $insert); ## traverse directory and insert $literal sub add_html { $tree-parse_file($file); ## operate on $file $ele-postinsert($literal); ## add literal } $tree-delete; $literal-delete; above code won't work unless i put all parts outside the sub into the sub. two questions : 1. will $tree-parse_file(parse a new file) will overwrite the old parsed $tree content? so that i dont have to delete the tree in the sub? 2. defining a static $literal outside the sub, then insert it during the sub. that will not work unless i define it inside the sub and delete it later in the sub. why can't i define it and use it over and again? the long program works but looks clumsy and made me curious.. find(\wanted,.); sub wanted { my $file = $_; return if ($file !~ /\.(html|htm)$/i); ## have to define it everytime ? my $tree = HTML::TreeBuilder-new; # empty tree $tree-no_space_compacting(1); $tree-store_comments(1); $tree-store_comments(1); $tree-store_declarations(1); $tree-parse_file($file); my $ele; for (@{ $tree-extract_links('a', 'href') }) { my($link, $element, $attr, $tag) = @$_; if ($link=~ m{/events\.htm}) { $ele = $element; last; } } unless ($ele) { $tree-delete; return; } print -- $file\n; $ele = $ele-parent(); #td $ele = $ele-parent(); #tr ## why can't keep it outside ?/ my $literal = HTML::Element-new('~literal','text' = $insert); $ele-postinsert($literal); open F,$file; print F $tree-as_HTML('',' ',{}); close F; $tree-delete; ## $literal-delete; } __ Do you Yahoo!? Yahoo! SiteBuilder - Free, easy-to-use web site design software http://sitebuilder.yahoo.com
RE: html tree question. clumsy ?
--- Thurn, Martin [EMAIL PROTECTED] wrote: I ran into similar problems for my module WWW::Search. No, out-of-the-box you can not re-use an HTML::TreeBuilder object to parse a new file. BUT you can use the following code as a reset. I.e. call parse, muck with the tree, do the following four lines, and call parse again. This does the same as new() but without changing the store_comments, store_pis settings, etc: $self-{'_head'} = $self-insert_element('head',1); $self-{'_pos'} = undef; # pull it back up $self-{'_body'} = $self-insert_element('body',1); $self-{'_pos'} = undef; # pull it back up again i will look into how that can be added to $tree later. but a reset method from HTML::TreeBuilder would be nice. The reason you can't re-use your HTML::Element is because it's a reference, and when the tree gets deleted, your Element gets deleted right along with it. - - Martin Thurn just found that $h-clone can get around this. too bad i can't do the same to a tree before it parses the file. from HTML::Element, You are free to clone HTML::TreeBuilder trees, just as long as: 1) they're done being parsed, or 2) you don't expect to resume parsing into the clone. (You can continue parsing into the original; it is never affected.) just to make sure, (english isn't my first language) does it say that i can't clone a tree if it doesn't parse something? Qiang __ Do you Yahoo!? Yahoo! SiteBuilder - Free, easy-to-use web site design software http://sitebuilder.yahoo.com
question with as_html output
I am trying to add html tag to an existing html file using HTML::TreeBuiler. the problem is that the added tags isn't encoded after the output. everything els is fine. ### my $tree = HTML::TreeBuilder-new; $tree-no_space_compacting(1); $tree-store_comments(1); $tree-parse_file(f.html); my $ele; my $tag = 'trtdTEST/td/tr'; for (@{ $tree-extract_links('a', 'href') }) { my($link, $element, $attr, $tag) = @$_; if ($link=~ m{/mylink\.htm}) { $ele = $element; last; } } $ele = $ele-parent(); # td $ele = $ele-parent(); # tr my $r = $ele-postinsert($tag); open F,f.html; print F $tree-as_HTML('',' ',{}); close F; $tree-delete; the output in html turn out to be lt;trgt;lt;tdgt;lt;bgt;TESTlt;/bgt;lt;/tdgt;lt;/trgt; what am i missing ? Qiang __ Do you Yahoo!? Yahoo! SiteBuilder - Free, easy-to-use web site design software http://sitebuilder.yahoo.com
Re: question with as_html output
--- Rob Dixon [EMAIL PROTECTED] wrote: James.Q.L wrote: I am trying to add html tag to an existing html file using HTML::TreeBuiler. the problem is that the added tags isn't encoded after the output. everything els is fine. ### my $tree = HTML::TreeBuilder-new; $tree-no_space_compacting(1); $tree-store_comments(1); $tree-parse_file(f.html); my $ele; my $tag = 'trtdTEST/td/tr'; for (@{ $tree-extract_links('a', 'href') }) { my($link, $element, $attr, $tag) = @$_; if ($link=~ m{/mylink\.htm}) { $ele = $element; last; } } $ele = $ele-parent(); # td $ele = $ele-parent(); # tr my $r = $ele-postinsert($tag); open F,f.html; print F $tree-as_HTML('',' ',{}); close F; $tree-delete; the output in html turn out to be lt;trgt;lt;tdgt;lt;bgt;TESTlt;/bgt;lt;/tdgt;lt;/trgt; The 'postinsert' method expects an HTML::Element object to add into the tree, not simple HTML text. The easiest way to build what you want here is probably with the 'new_from_lol' method like this. my $tag = HTML::Element-new_from_lol (['tr', ['td', 'TEST']]) HTH, Rob From HTML::Element doc, $h-postinsert($element_or_text...) i suppose it means postinsert accept $element or text. and the insertion didn't yield any error with text as parameter.and it looks much simpler/easier than the new_from_lol. using HTML::Element-new_from_lol (['tr', ['td', 'TEST']]) did lead to the correct html output. but when i am not using 'TEST' directly in new_from_lol $insert= TEST; trtdsome more tags here/td/tr TEST $h = HTML::Element-new_from_lol (['tr', ['td', $insert]]); then do postinsert($h); the tags in $insert still don't get decoded after output. any idea? Qiang __ Do you Yahoo!? Yahoo! SiteBuilder - Free, easy-to-use web site design software http://sitebuilder.yahoo.com