Re: need help cleaning up a search



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"

.



Relevant Pages

  • Re: [PHP] Re: Not getting expected result from file()
    ... If you are not able to get anything into your DB (and your connection is ok), then two things might be wrong: your input or the query string itself. ... I'm using the file function create an array. ...
    (php.general)
  • Re: Find flagstatus
    ... I wouldn't ask you this if the folder where I should find these mailitems ... or query!? ... but I'll probably stick with the "for each" script I ... I always think it's a good idea to create the query string with a separate ...
    (microsoft.public.office.developer.outlook.vba)
  • RE: Export from Access 2007 Report to excel
    ... Here's a code snippet of a workaround I use which outputs to a datasheet ... This gets the query string from the recordsource for the report that is ... using the output to macro command, choosing a Report name, and choosing Excel ...
    (microsoft.public.access.externaldata)
  • re: using the ?query string appended to ASP url
    ... a query string can provide input to criteria that you ... specify in the Datbase Results Wizard. ... The only limitation is that FrontPage ...
    (microsoft.public.frontpage.client)
  • Re: complex search engine
    ... the query string. ... Basically, for each query string, start at state 0. ... If the next character in the match string is %, ... Now that I look at my explanation, I realize I haven't done a good job explaining how to combine states. ...
    (comp.programming)