GoFuckYourself.com - Adult Webmaster Forum

GoFuckYourself.com - Adult Webmaster Forum (https://gfy.com/index.php)
-   Fucking Around & Business Discussion (https://gfy.com/forumdisplay.php?f=26)
-   -   perl question (https://gfy.com/showthread.php?t=1024245)

fris 05-26-2011 05:35 PM

perl question
 
is their something like mechanize for a local file?


Code:

#!/usr/local/bin/perl

use WWW::Mechanize;

binmode(STDOUT, ":utf8");

my $url  = "http://domain.com/bookmarks.html";
my $mech  = WWW::Mechanize->new();
$mech->get( $url );
my @links = $mech->links();

foreach my $link (@links) {
  print $link->url() . "|" . $link->text() . "\n";
}

like this but for a local file?

Tempest 05-26-2011 07:04 PM

No idea.. I've always user HTML::TokeParser

Barry-xlovecam 05-26-2011 08:42 PM

split=/regex/ works
 
This looks sort of nasty but works.
I used a Firefox bookmarks file.
Some adjustments to the splits might be necessary for their regexes ...

You don't need to use some complex module to manipulate a line of text in Perl.
Perl has a very complex and efficient regex engine in its core distribution.
I am sure there are more elegant ways to regex this but this works :)

Code:

#!/usr/bin/perl
####################################
#bookmarkfile.cgi
#
#
#
#
####################################
use CGI::Carp qw/fatalsToBrowser/;
use CGI qw/:standard/;
use strict;
use warnings;

print "Content-type: text/html\n\n";

my $mystuff = "$ENV{'QUERY_STRING'}";
        if ($mystuff =~ s/[^a-zA-Z0-9\_]//g) {print qq~HUH???~;      exit;}

my $bookmarkfile="barry-bookmarks-6-2010.html";

open BOOKMARKFILE ,"<",$bookmarkfile or die "<bookmarkfile";

#######SAMPLE LINE
#        <DT><A HREF="http://trends.google.com/websites?q=xlovecam.com&geo=all&date=all&sort=0
#" ADD_DATE="1274745854" LAST_MODIFIED="1274745854">Google Trends for Websites: xlovecam.com</A>
#######

my @bookmarks=(<BOOKMARKFILE>);

        my @urls = grep /(http:)/, @bookmarks;

                        foreach my $urls (@urls){
                                my @a= split /HREF=\"/, $urls;
                                my @b= split /" ADD_DATE/,$a[1];
                                my @anchor1 = split />/, $a[1];
                                my @anchor = split /</, $anchor1[1];

                                print "$b[0]|$anchor[0]<br/>\n";
                            }

outputs:
Code:

http://trends.google.com/websites?q=xlovecam.com&geo=all&date=all&sort=0|Google Trends for Websites: xlovecam.com

DangerX !!! 05-26-2011 10:04 PM

I will ask my girl later, she does a lot of Perl. Myself, I've always preferred Python over Perl, much cleaner etc.

fris 05-27-2011 03:25 AM

actually instead of http://domain.com/bookmarks.html file:bookmarks.html works

Barry-xlovecam 05-27-2011 07:24 AM

open the read file <
open the write file if necessary > or >>

print WRITEFILE "data ...\n";

If a module will handle many events install it. Problem is in the module installation. There are a lot of cases where users do not have access to root and use of the CPAN shell.

Considering your prior attempt at using sed for this, I am assuming this is for local use of some sort.

WWW::Mechanize is an interesting module.

u-Bob 05-27-2011 07:47 AM

could always use the update_html method </ugly hack>

fris 06-05-2011 07:33 AM

Quote:

Originally Posted by Barry-xlovecam (Post 18170723)
open the read file <
open the write file if necessary > or >>

print WRITEFILE "data ...\n";

If a module will handle many events install it. Problem is in the module installation. There are a lot of cases where users do not have access to root and use of the CPAN shell.

Considering your prior attempt at using sed for this, I am assuming this is for local use of some sort.

WWW::Mechanize is an interesting module.

ya just for local, to take the bookmarks and just make <a href links from console, cause chrome bookmark export is ugly with tables.


All times are GMT -7. The time now is 09:34 AM.

Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
©2000-, AI Media Network Inc