finding contents from string

Arnaud Delobelle arnodel at googlemail.com
Tue Feb 16 11:57:59 CET 2010


danin <gawade.ninad at gmail.com> writes:

> Hi all,
>         I am looking for particular solution. I am having one string
> say:
> string- "http://maps.google.co.in/maps/ms?
> hl=en&ie=UTF8&msa=0&msid=106178526636832397420.00047fb46fa8d02481f09&ll=20.730428,86.456909&spn=2.178194,3.526611&z=8
> "
>           and from this string  i need to extract value
> -20.730428,86.456909. These value are dynamic so i cant use filter. So
> can anyone please tell me about how to do this.

In Python 2.5:

>>> import urlparse
>>> url='http://www.example.com/foo?bar=42&spam=eggs'
>>> parsed_url = urlparse.urlparse(url)
>>> parsed_url.query
'bar=42&spam=eggs'
>>> import cgi
>>> parsed_query = cgi.parse_qs(parsed_url.query)
>>> parsed_query
{'bar': ['42'], 'spam': ['eggs']}

In Python >= 2.6, parse_qs lives in the urlparse module as well.

-- 
Arnaud



More information about the Python-list mailing list