[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.python

finding contents from string

danin

2/16/2010 10:43:00 AM

Hi all,
I am looking for particular solution. I am having one string
say:
string- "http://maps.google.co.i...
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.
3 Answers

Arnaud Delobelle

2/16/2010 10:58:00 AM

0

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

> Hi all,
> I am looking for particular solution. I am having one string
> say:
> string- "http://maps.google.co.i...
> 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...
>>> 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

Peter Otten

2/16/2010 11:00:00 AM

0

danin wrote:

> Hi all,
> I am looking for particular solution. I am having one string
> say:
> string- "http://maps.google.co.i...
>
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.

Where does the "-" come from?

> These value are dynamic so i cant use filter.

I don't understand.

> So can anyone please tell me about how to do this.

>>> from urlparse import urlparse, parse_qs
>>> parse_qs(urlparse(string).query)["ll"][0]
'20.730428,86.456909'

Peter

Lars Behrens

2/16/2010 11:26:00 AM

0

danin wrote:

> can anyone please tell me about how to do this.

Now come on, you have to give a *bit* more information. What have you done
so far? What did you plan? What are the rules for finding the string?

--
Cheerz Lars