有裏urlparse一個功能「裏urlparse」和「parse_qs」可靠地訪問這些數據,如下圖所示
$ python
Python 2.6.6 (r266:84292, Jul 23 2015, 15:22:56)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-11)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> u="""https://www.testweb.com/cordi?ll=41.403781,2.1896&z=17&pll=41.403781,2.1896"""
>>> import urlparse
>>> x=urlparse.urlparse(u)
>>> x
ParseResult(scheme='https', netloc='www.testweb.com', path='/cordi', params='', query='ll=41.403781,2.1896&z=17&pll=41.403781,2.1896', fragment='')
>>> x.query
'll=41.403781,2.1896&z=17&pll=41.403781,2.1896'
>>> urlparse.parse_qs(x.query)
{'ll': ['41.403781,2.1896'], 'z': ['17'], 'pll': ['41.403781,2.1896']}
>>>
肯定有一個體面的URL解析爲Python在那裏? – Biffen
它總是出現在URL的最後?因爲如果是這種情況,那麼'[\ d。,] + $'將會完成這項工作。 [Demo](https://regex101.com/r/rB7mF9/2) –
謝謝Biffen,我會看看是否存在一些東西。是的@noob這是總是模式。 – Shudy