Sunday, February 03, 2013

Elinks pre_format_html using perl

Elinks is a fantastic text based browser. It also provide HTML re-writing. You can see HTM re-writing as your grease monkey script to update the HTML of the page. Elinks supports HTML re-writing using Lua, Ruby and perl.

To implement HTML re-writing using perl, create a file called under ~/.elinks. You can implement various hooks (see example file or search google for elinks manual and HTML rewriting). I have implemented pre_format_html_hook and here is my code.

Blogger does not allow me to use angular brackets in my code. You need to make following changes to the code:
*Replace LESSTHANSIGN with actual HTML start tag angular bracket.
*Replace GREATERTHANSIGN with actual HTML end tag angular bracket.

sub pre_format_html_hook
 my $url = shift;
 my $html = shift;

 if ($url =~ 'google\.com')
        # User .*? to not use greedy pattern matching.
        $html =~ s/LESSTHANSIGNdiv id=.*?gbar.*?\/divGREATERTHANSIGN//;
        $html =~ s/LESSTHANSIGNdiv id=.*?modeselector.*?\/divGREATERTHANSIGN//;
        $html =~ s/LESSTHANSIGNdivGREATERTHANSIGNLESSTHANSIGNh2 class=\"hd\">Search Options.*?\/divGREATERTHANSIGN//;

 return $html;

No comments:

Post a Comment