Welcome to the GoFuckYourself.com - Adult Webmaster Forum forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Post New Thread Reply

Register GFY Rules Calendar Mark Forums Read
Go Back   GoFuckYourself.com - Adult Webmaster Forum > >
Discuss what's fucking going on, and which programs are best and worst. One-time "program" announcements from "established" webmasters are allowed.

 
Thread Tools
Old 05-26-2011, 05:35 PM   #1
fris
Too lazy to set a custom title
 
fris's Avatar
 
Industry Role:
Join Date: Aug 2002
Posts: 55,232
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?
__________________
Since 1999: 69 Adult Industry awards for Best Hosting Company and professional excellence.


WP Stuff
fris is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 05-26-2011, 07:04 PM   #2
Tempest
Too lazy to set a custom title
 
Industry Role:
Join Date: May 2004
Location: West Coast, Canada.
Posts: 10,217
No idea.. I've always user HTML::TokeParser
Tempest is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 05-26-2011, 08:42 PM   #3
Barry-xlovecam
It's 42
 
Industry Role:
Join Date: Jun 2010
Location: Global
Posts: 18,083
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

Last edited by Barry-xlovecam; 05-26-2011 at 08:48 PM..
Barry-xlovecam is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 05-26-2011, 10:04 PM   #4
DangerX !!!
Confirmed User
 
DangerX !!!'s Avatar
 
Industry Role:
Join Date: Feb 2011
Location: La Isla Bonita Power Level: ❤❤❤❤❤❤❤❤❤❤
Posts: 886
I will ask my girl later, she does a lot of Perl. Myself, I've always preferred Python over Perl, much cleaner etc.
__________________
This is sig area!
DangerX !!! is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 05-27-2011, 03:25 AM   #5
fris
Too lazy to set a custom title
 
fris's Avatar
 
Industry Role:
Join Date: Aug 2002
Posts: 55,232
actually instead of http://domain.com/bookmarks.html file:bookmarks.html works
__________________
Since 1999: 69 Adult Industry awards for Best Hosting Company and professional excellence.


WP Stuff
fris is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 05-27-2011, 07:24 AM   #6
Barry-xlovecam
It's 42
 
Industry Role:
Join Date: Jun 2010
Location: Global
Posts: 18,083
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.
Barry-xlovecam is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 05-27-2011, 07:47 AM   #7
u-Bob
there's no $$$ in porn
 
u-Bob's Avatar
 
Industry Role:
Join Date: Jul 2005
Location: icq: 195./568.-230 (btw: not getting offline msgs)
Posts: 33,063
could always use the update_html method </ugly hack>
u-Bob is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 06-05-2011, 07:33 AM   #8
fris
Too lazy to set a custom title
 
fris's Avatar
 
Industry Role:
Join Date: Aug 2002
Posts: 55,232
Quote:
Originally Posted by Barry-xlovecam View Post
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.
__________________
Since 1999: 69 Adult Industry awards for Best Hosting Company and professional excellence.


WP Stuff
fris is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Post New Thread Reply
Go Back   GoFuckYourself.com - Adult Webmaster Forum > >

Bookmarks
Thread Tools



Advertising inquiries - marketing at gfy dot com

Contact Admin - Advertise - GFY Rules - Top

©2000-, AI Media Network Inc



Powered by vBulletin
Copyright © 2000- Jelsoft Enterprises Limited.