Search
Documents
Netscape::History - object class for accessing Netscape history database (Displayed) README
|
Netscape::History - object class for accessing Netscape history database
Netscape::History - object class for accessing Netscape history database
use Netscape::History;
$history = new Netscape::History();
while (defined($url = $history->next_url() ))
{
}
The Netscape::History module implements an object class for
accessing the history database maintained by the Netscape web browser.
The history database keeps a list of all URLs you have visited,
and is used by Netscape to change the color of URLs which you have
previously visited, for example.
With this module, you can get at the URLs stored in a Netscape history
file, delete URLs, and add new ones. With the associated
Netscape::HistoryURL module you can access the information which
is associated with each URL.
Please Note: the database format for the browser history was changed
with Netscape 4. Previously only the time of most recent visit was
available; now you can also get at the time of your first visit,
the number of visits, the title of the referenced page, and another value.
$history = Netscape::History->new();
This creates a new instance of the Netscape::History object class.
You can optionally pass the path to the history database as an
argument to the constructor, as in:
$history = Netscape::History->new('/home/bob/.netscape/history.db');
If you do not specify the file, then the constructor will use:
$HOME/.netscape/history.db
If the Netscape history database does not exist, a warning message
will be generated, and the constructor will return undef.
The Netscape::History class implements the following methods:
get_url - get a specific URL from your history
rewind - reset history database to first URL
next_url - get next URL from your history
delete_url - remove a URL from your history
add_url - add a URL to the history file
close - close the history database
Each of the methods is described separately below.
$url = $history->get_url( URL );
This method is used to extract information about a specific URL
from your history database.
This method takes a URL (which could be just a text string,
or an object of class URI::URL) and returns an instance
of Netscape::HistoryURL.
$url = $history->next_url();
This method returns the next URL from your history database.
If you want to process all URLs in the database, you
should call the rewind method before looping over all URLs.
The URL returned is an instance of the Netscape::HistoryURL class,
which works just like an instance of URI::URL, but provides an
extra methods, as described in the documentation for Netscape::HistoryURL.
$history->delete_url($url);
This method is used to remove a URL from your history database.
The URL passed can be a simple text string with the URL,
or an instance of Netscape::HistoryURL, URI::URL, or any other
class which can be rendered into a string.
$history->add_url( URL );
This method is used to add a URL to a history database.
This might be useful if you are merging information from multiple
history databases, for example.
If the URL passed is an instance of Netscape::HistoryURL,
then the information available will be stored.
If the URL is specified as a text string, is derived from URI::URL,
then a Netscape::HistoryURL will be created with the following:
LAST = current time
FIRST = current time
COUNT = 1
EXPIRE = 1
TITLE = ''
If the EXPIRE field is not set to 1, then it won't appear
in Netscape's history window. Not really sure why :-)
$history->rewind();
This method is used to move the history database's internal pointer
to the first URL in your history database.
You don't need to bother with this if you have just created the object,
but it doesn't harm anything if you do.
$history->close();
This closes the history database. The destructor will do this automatically
for you, so most of time you don't actually have to bother calling this
method explicitly. Good programming style says you should though :-)
The following example illustrates use of this module,
and the visit_time() method of the URLs returned.
The program will list all URLs visited, along with visit time.
The Date::Format module is used to format the visit time.
#!/usr/bin/perl -w
use Netscape::History;
use Date::Format;
use strict;
my $history;
my $url;
$history = new Netscape::History;
while (defined($url = $history->next_url() ))
{
print "$url :\n";
print " First : ", ctime($url->first_visit_time());
print " Last : ", ctime($url->last_visit_time());
print " Count : ", $url->visit_count(), "\n";
print " Expire : ", $url->expire(), "\n";
print " Title : ", $url->title(), "\n";
}
$history->close();
The following example illustrates use of the add_url method
to merge two history databases. We read all URLs from history2.db,
and merge them into history1.db, overwriting any duplicates.
$history1 = new Netscape::History("history1.db");
$history2 = new Netscape::History("history2.db");
while (defined($url = $history2->next_url() ))
{
$history1->add_url($url);
}
$history1->close();
$history2->close();
- the Netscape::HistoryURL manpage
-
When you call the next_url method, you are returned instances of this class.
- DB_File
-
The Netscape history file is just a Berkeley DB File,
which we access using the
DB_File module. You can
use a different DB_File compatible library (such as
DB_File::SV185) by running
-
use Netscape::History dblib => 'DB_File::SV185'
-
in which case you are only depending on the specified
library and not DB_File.
- the URI::URL manpage
-
The underlying class for the Netscape::HistoryURL manpage,
which provides the mechanisms for manipulating URLs.
- the Date::Format manpage
-
Functions for formatting time and date in strings.
Neil Bowers <neilb@cre.canon.co.uk>, and
Richard Taylor <rit@cre.canon.co.uk>.
Copyright (c) 1997-2000 Canon Research Centre Europe. All rights reserved.
This module is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
Information
|
This site is currently in testing, it is not yet operating using the full database. Until it is officially launched you may wish to visit Help-Site Computer Manuals. After launch, this site (HelpSpy) will replace Help-Site. Information about the spider which is currently trawling the Internet looking for links to add to this directory can be found here. |
|