[MOBY-l] simple MOBY screen-scraper code

Mark Wilkinson markw at illuminae.com
Wed Mar 17 18:42:03 UTC 2004


Weird!  in my "sent" box, it has an attachment, and in my MOBY inbox it says it
has an attachment, but the attachment is missing!

Here is a re-send, with attachment again, but here is the code in-line to make
sure it actually gets to you...

#!/usr/bin/perl -w
use strict;

#=============================
# you need to provide these...

my $auth = $ARGV[0];
my $service= $ARGV[1];
my $namespace = $ARGV[2];
my $id = $ARGV[3];

#==============================


# URL encode
$auth =~s/([^a-zA-Z0-9_\-.])/uc sprintf("%%%02x",ord($1))/eg;
$service =~s/([^a-zA-Z0-9_\-.])/uc sprintf("%%%02x",ord($1))/eg;
$namespace =~s/([^a-zA-Z0-9_\-.])/uc sprintf("%%%02x",ord($1))/eg;
$id =~s/([^a-zA-Z0-9_\-.])/uc sprintf("%%%02x",ord($1))/eg;

use LWP::UserAgent;
my $ua = LWP::UserAgent->new;
# Initialize proxy settings from environment variables
$ua->env_proxy;
# Create a request
my $req = HTTP::Request->new(GET =>
"http://mobycentral.cbr.nrc.ca/cgi-bin/gbrowse_moby?authority=$auth;servicename=$service;namespace=$namespace;id=$id");
$req->header('Accept' => 'text/html');
# Pass request to the user agent and get a respnse back
my $res = $ua->request($req);
# Check the outcome of the response
unless  ($res->is_success) {
    return;
}

my $content = $res->content;
my @tablerows = $content =~
/SCRAPE_ME_START\s*\-\-\s*\>(.*?)\<\!\s*\-\-\s*SCRAPE_ME_END/g;

print "<table width = 100%><tr><td> MOBY results</td></tr>\n";
print "<tr><td>\n";
print "<table border = 1>\n";
foreach (@tablerows){
    print;
    print "\n";
}
print "</table>\n";
print "</td></tr></table>\n";


Original Message===============================

Rebecca requested this from me this morning (in exchange for setting up
some services for me at MIPS :-) ).  It may be useful to others, so I am
sending it to the list.

This code takes the authority, servicename, namespace, and id and makes
the call to the service, then prints an HTML table of the results via
screen-scraping the moby client CGI's output.

Modify this as you wish for your own purposes.

M


-- 
Mark Wilkinson (mwilkinson at mrl.ubc.ca)
University of British Columbia iCAPTURE Centre


More information about the moby-l mailing list