0

I need to create a script that accesses a website, submits a query, 'clicks' on one of the hits, and sends back the url of the result. What I'm stuck on is submitting the query in the first place. Here is what I have:

use strict;
use warnings;
use LWP::UserAgent;
my $entry = $ARGV[0] or die;
my $url = 'http://genome.ucsc.edu/cgi-bin/hgBlat?hgsid=502819467_w6Oj12MTSqOIIJuSjAKsza4x9yeA&command=start';
my $browser = LWP::UserAgent->new;
my $response = $browser->post(
  '$url',
  [
    'sequence'  => $entry,
    'search' => 'submit'
  ],
);
die "Error: ", $response->status_line
 unless $response->is_success;

I keep getting this error: Error: 400 URL must be absolute at LWPtest.pl line 14. Can someone explain what this means, and how I should fix the problem? Also how do I approach the "'clicks' on one of the hits, and sends back the url of the result" bit?

EDIT:

I found this on the website in question:

When including a Genome Browser URL, please remove the hgsid parameter. It is an internally-used parameter that expires after about a day.

Not sure if this is part of the problem; it may become a problem after "about a day".

Community
  • 1
  • 1
Aditya J.
  • 131
  • 2
  • 11
  • For your use-case, https://metacpan.org/pod/WWW::Mechanize makes more sense than using LWP::UserAgent. It's a subclass that makes clicking easier and basically behaves like a browser without JavaScript support. – simbabque Aug 09 '16 at 15:49

2 Answers2

1

$url on line ~10 in single quotes, which means that it is the character sequence $ u r l instead of the value of the variable $url.

'$url',

to

$url,
Aditya J.
  • 131
  • 2
  • 11
Tim Tom
  • 779
  • 3
  • 6
  • 1
    To make your answer better, you should include that full statement from the code, and show how what to do instead. – simbabque Aug 09 '16 at 15:50
1

The code

'$url'

produces the 4-character string

$url

instead of

http://genome.ucsc.edu/cgi-bin/hgBlat?hgsid=502819467_w6Oj12MTSqOIIJuSjAKsza4x9yeA&command=start

Simply replace

'$url'

with

$url
ikegami
  • 367,544
  • 15
  • 269
  • 518