Re: need help cleaning up a search
- From: rob.dixon@xxxxxxx (Rob Dixon)
- Date: Sat, 27 Jan 2007 09:17:21 +0000
FamiLink Admin wrote:
> Hello all,
>
> I am using the following to pull a search query from a google search:
>
> ( my $search1 ) = $url =~ /q=(.*)/;
> my $search = (split '&', $search1)[0];
>
> If the search looks at this string:
>
> http://www.google.com/search?hl=en&q=+erika+michelle+barre&btnG=Google+Search
>
>
> Then my search = +erika+michelle+barre
>
> How would I chop off any funny characters (+, %, -, ...) from the front
> of the results (and off the end for that mater)
>
> Sometimes there are even +++ before the text I need to get.
The process of escaping a URL replaces spaces with plus signs, and these are
appearing at the start of your query string because you have leading spaces in
the original query. It is best to use the URI module to unescape the URL and
retrieve the original query string before adjusting it any further. The program
below extracts all of the query into hash %query, and so has values for keys
'hl', 'q', and 'btnG'. It is then a simple matter to remove leading and trailing
spaces from the query value.
HTH,
Rob
use strict;
use warnings;
use URI;
my $url = URI->new('http://www.google.com/search?hl=en&q=+erika+michelle+barre&btnG=Google+Search');
my %query = $url->query_form;
my $q = $query{q};
print qq("$q"\n);
**OUTPUT**
" erika michelle barre"
.
- References:
- Use of uninitialized value in string eq
- From: Jen Spinney
- Re: Use of uninitialized value in string eq
- From: Rob Dixon
- need help cleaning up a search
- From: FamiLink Admin
- Use of uninitialized value in string eq
- Prev by Date: Re: writing a file in IIS
- Next by Date: Re: parsing XML
- Previous by thread: Re: need help cleaning up a search
- Next by thread: writing a file in IIS
- Index(es):
Relevant Pages
|