[Chicago-talk] ItemId

petemar1 petemar1 at perlmonk.org
Tue Jan 6 12:58:25 CST 2004


I'm trying to get multiple Item ID numbers from a completed eBay search
page.

I've tried a similar method using Java. In both instances I can only scrape
one id from the page instead of all of them. I thought of using a while loop
(commented out below) that continues until the regex returns false. I went
through the hassle of logging in, fllowing the search link and then the
advanced search link and submitting the search rather than linking to the
completed search directly.

Any ideas?



#!/usr/local/bin/perl -w

use strict;
use warnings;
use FindBin::libs;
use WWW::Mechanize;
use LWP::UserAgent;
use HTTP::Request;
use HTTP::Response;
use URI::Heuristic;

my $url;
my $ua;
my $req;
my $response;
my $content;
my $title;

my $sec;
my $min;
my $hour;
my $mday;
my $mon;
my $year;
my $wday;
my $yday;
my $isdst;
my $realmonth;
my $realday;
my $realyear;
($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) =
localtime(time);
$realmonth = $mon + 1;
$realday = $mday - 1;
$realyear = $year + 1900;

my $user    = 'username';
my $pass    = 'password';
# my $message = 'Testing...';

my $a = WWW::Mechanize->new();
#$a->get('http://search-completed.ebay.com/search/search.dll?GetResult&rfisa
ctive=1&region=0&max
recordsperpage=50&from=R14&query=canon+digital+camera+-battery+-case+-cable+
-card+-memory+-camco
rder&ht=1&completedonly=1');
$a->get('http://signin.ebay.com/aw-cgi/eBayISAPI.dll?SignIn&UsingSSL=0&pUser
Id=aneyusor&ru=http%
3A%2F%2Fcgi1.ebay.com%2Faw-cgi%2FeBayISAPI.dll%3FMyEbayLogin&pp=pass&pageTyp
e=174&i1=0');

$a->submit_form(
   form_number => 2,
   fields => {
      userid   => $user,
      pass => $pass,
   },
);

print "logged in!\n";

$a->follow_link('http://pages.ebay.com/search/items/basicsearch.html?ssPageN
ame=h:h:fitem:US');
print "Moved to Search page!\n";

$a->follow_link('http://pages.ebay.com/search/items/search_adv.html');
print "Moved to Advanced Search page!\n";


my $littlesearch = $a->submit_form(
   form_number => 1,
   fields => {
      ht => '1',
      query => 'canon digital camera',
#      exclude => 'battery case cable card memory camcorder',
#      completedOnly => '1',
#      maxRecordsPerPage => '100',
   },
);


#print "submitted search!\n";


##########

$url =
URI::Heuristic::uf_urlstr("http://search-completed.ebay.com/search/search.dl
l?GetResult&r
fisactive=1&region=0&maxrecordsperpage=50&from=R14&query=canon+digital+camer
a+-battery+-case+-ca
ble+-card+-memory+-camcorder&ht=1&completedonly=1");
#$| = 1;

#$ua = LWP::UserAgent->new();
#$ua->agent("Mozilla/v5.0");
#$req = HTTP::Request->new(GET => $url);
#$req->referer("http://localhost.localdomain");

#$a->get('http://search-completed.ebay.com/search/search.dll?GetResult&rfisa
ctive=1&region=0&max
recordsperpage=100&from=R14&query=canon+digital+camera+-battery+-case+-cable
+-card+-memory+-camc
order&ht=1&completedonly=1');
#$a->get($url);

print "\nGetting url...\n";

#$response = $a->request($req);
#$response = $a->get($url);
$response = $littlesearch;
if ($response->is_error())
{
        printf "%s\n", $response->status_line;
}
else
{
        $title = $response->title();
        $content = $response->content();

        open(NETDATA, ">>netdata.txt");

        printf "\nFrom: %s\n", $title;
        print NETDATA "\n";

        printf NETDATA "%02d/%02d/%04d, %02d:%02d:%02d CST\n",
$realmonth,$mday,$realyear,$hour,
$min,$sec;
        print "\n";

#  while($content != <>){
        print NETDATA "ITEM ID : ";
        #print NETDATA $content =~
m/ViewItem&amp;item=(.*?)&amp;category=/s;
        print NETDATA $content =~ m/ViewItem&amp;item=(\d*)&amp;category=/s;
        print NETDATA "\n";
#  }


        close(NETDATA);

}


print "\n";
print "\nDone! Exiting.\n";
exit;





More information about the Chicago-talk mailing list