What I've done so far, is capture about 885 different URLs of content that users have been using, and stored the url, name, etc. in a database. Nothing magical there. When the user wants to select some content to convert for their Palm, they pick from a list of sites in the database, and are shown a "preview" of what it might look like when it gets onto their handheld in our application.
The problem with the approach I'm using, currently an iframe as shown in the first code snippet below, is that our list of "previews" is subject to whatever HTML the remote site we're pointing to for the iframe decides they want to use, including any broken HTML, maliscious HTML or javascript, meta-refresh tags, popups, and other noise.
# The URL itself is queried from the database above here, # but that isn't important for this particular explanation # # The URL itself is stored in $url_uri from bind_col() while ($sth->fetch) { my $substr_url_uri; $substr_url_uri = length ($url_uri) > 60 ? substr($url_uri,0,60) . "..." : $url_uri; print br(), "\n"x3, start_div({-class=>'urlbox'}), span({-class=>'urlinfo'}, b("$url_name"), br(), br(), "Current category:", start_span({-class=>'catname'}), $category_name, end_span(), br()x2, start_span({-class=>'catlist'}), "Move to new category:", br(), popup_menu("category", \@categories), end_span(), ), end_div(), start_div({-class=>'urlprev'}), start_iframe({-src => "$url_uri", -width => '170', -height => '170', -scrolling => 'no', -marginwidth => '1', -marginheight => '1', -frameborder => '0',}), end_iframe, end_div(), } $sth->finish;
Obviously this presents a problem when we have a really nice looking interface for the previews, similar to those in this screenshot.
What I'm wondering, is if it is possible to take a screenshot of the content on the remote site, in the same 160x160 window, and present that screenshot to the user in the preview, instead of an iframe pointing directly at the live, remote (raw) content? I know I can fetch the content with LWP::UserAgent, using the following (working) snippet:
sub fetch_url { my $url_uri = shift; my $ua = LWP::UserAgent->new; $ua->agent('Mozilla/3.0'); my $url = "$url_uri"; my $request = HTTP::Request->new(GET => $url); my $response = $ua->request($request); # Content itself is in $response->content; here. return $response->content; }
Using an image, however, presents us with a few good advantages:
I can also use LWP::Simple's getstore() function or fetch the content and store it in a local file directly using the snippet above, such as:
I'd rather stay away from that for a few reasons:open(CONTENT, ">content.$$") or die $! print CONTENT $response->content; close CONTENT;
So the question is, does there exist a way to do this programatically?
Is it possible to print the content stored in $response->content; above and create an image out of the contents?
Can I jam the content into some sort of postscript filter, and then print that to an image?
Is there some merlyn column on exactly this topic somewhere on stonehenge?
Has anyone done anything remotely similar to this?
In reply to Automated Screenshot Grabbing via LWP? by hacker
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |