urlparse

>>> prourl=u'http://product.gongchang.com/s3946/CNS2900183019.html?gct=13.0.1-4&a=1&b=2&c=3'html

>>> import urlparseurl

>>> import urllibspa

>>> urlobj=urlparse.urlparse(prourl.encode("utf8"))code

>>> h=list(urlobj)htm

>>> hget

['http', 'product.gongchang.com', '/s3946/CNS2900183019.html', '', 'gct=13.0.1-4&a=1&b=2&c=3', '']ast

>>> query=urlobj.queryimport

>>> querymodule

'gct=13.0.1-4&a=1&b=2&c=3'gc

>>> para_dict=dict(urlparse.parse_qsl(query))   空值不算  ||para_dict=dict(urlparse.parse_qsl(query,1))

>>> para_dict

{'a': '1', 'c': '3', 'b': '2', 'gct': '13.0.1-4'}

>>> prlist[4] = urllib.urlencode(para_dict)

Traceback (most recent call last):

  File "<stdin>", line 1, in <module>

NameError: name 'prlist' is not defined

>>> h[4] = urllib.urlencode(para_dict)

>>> h

['http', 'product.gongchang.com', '/s3946/CNS2900183019.html', '', 'a=1&c=3&b=2&gct=13.0.1-4&d=4', '']

>>> urlparse.ParseResult(*h).geturl()  

'http://product.gongchang.com/s3946/CNS2900183019.html?a=1&c=3&b=2&gct=13.0.1-4&d=4'

相關文章
相關標籤/搜索