2015-11-04 66 views
2

我有一個網址http://maps.google.be/maps?q=&layer=c&cbll=50.8091411000,5.0198822000&cbp=0,0,0,0,0剝離的動態URL內容

我要分析它,並從URL中獲取經緯度與關鍵字cbll值長度可能會有所不同。即我想要在cbll=&之後得到值。

我該怎麼做?

回答

3

使用string.split

string.split('cbll=')[1].split('&')[0] 

所以這將是,

lat, long = string.split('cbll=')[1].split('&')[0].split(',') 

例子:

>>> url = 'http://maps.google.be/maps?q=&layer=c&cbll=50.8091411000,5.0198822000&cbp=0,0,0,0,0' 
>>> url.split('cbll=')[1].split('&')[0].split(',') 
['50.8091411000', '5.0198822000'] 
+0

你是真棒! – user3383301