python 中的正则表达式与 urlParse
Regular expression in python with urlParse
我有这个URL:
https://www.yoursite.com/drive/team-real-431/pepe-ozil-R323/anyway-jim-james-hi-bye-hi-321312/;jsessionid=DBDE454034B0EE325FC100112EF2E123.56AC29295781342F53AB242D03EE33
我想要
DBDE454034B0EE325FC100112EF2E123.56AC29295781342F53AB242D03EE33
我试过了
ulrJS = "https://www.yoursite.com/drive/team-real-431/pepe-ozil-R323/anyway-jim-james-hi-bye-hi-321312/;jsessionid=DBDE454034B0EE325FC100112EF2E123.56AC29295781342F53AB242D03EE33"
ulrJS = ulrJS.split('/')[-1]
您可以使用 urlparse
:
>>> import urlparse
>>> url = 'https://www.yoursite.com/drive/team-real-431/pepe-ozil-R323/anyway-jim-james-hi-bye-hi-321312/;jsessionid=DBDE454034B0EE325FC100112EF2E123.56AC29295781342F53AB242D03EE33'
>>> url_parts = urlparse.urlparse(url)
>>> jsessionid = dict(urlparse.parse_qsl(url_parts.params)).get('jsessionid')
>>> print(jsessionid)
DBDE454034B0EE325FC100112EF2E123.56AC29295781342F53AB242D03EE33
from urlparse import urlparse
url ="https://www.yoursite.com/drive/team-real-431/pepe-ozil-R323/anyway-jim-james-hi-bye-hi-321312/;jsessionid=DBDE454034B0EE325FC100112EF2E123.56AC29295781342F53AB242D03EE33"
u = urlparse(url)
print u.params.split("=")[1]
'DBDE454034B0EE325FC100112EF2E123.56AC29295781342F53AB242D03EE33'
我有这个URL:
https://www.yoursite.com/drive/team-real-431/pepe-ozil-R323/anyway-jim-james-hi-bye-hi-321312/;jsessionid=DBDE454034B0EE325FC100112EF2E123.56AC29295781342F53AB242D03EE33
我想要
DBDE454034B0EE325FC100112EF2E123.56AC29295781342F53AB242D03EE33
我试过了
ulrJS = "https://www.yoursite.com/drive/team-real-431/pepe-ozil-R323/anyway-jim-james-hi-bye-hi-321312/;jsessionid=DBDE454034B0EE325FC100112EF2E123.56AC29295781342F53AB242D03EE33"
ulrJS = ulrJS.split('/')[-1]
您可以使用 urlparse
:
>>> import urlparse
>>> url = 'https://www.yoursite.com/drive/team-real-431/pepe-ozil-R323/anyway-jim-james-hi-bye-hi-321312/;jsessionid=DBDE454034B0EE325FC100112EF2E123.56AC29295781342F53AB242D03EE33'
>>> url_parts = urlparse.urlparse(url)
>>> jsessionid = dict(urlparse.parse_qsl(url_parts.params)).get('jsessionid')
>>> print(jsessionid)
DBDE454034B0EE325FC100112EF2E123.56AC29295781342F53AB242D03EE33
from urlparse import urlparse
url ="https://www.yoursite.com/drive/team-real-431/pepe-ozil-R323/anyway-jim-james-hi-bye-hi-321312/;jsessionid=DBDE454034B0EE325FC100112EF2E123.56AC29295781342F53AB242D03EE33"
u = urlparse(url)
print u.params.split("=")[1]
'DBDE454034B0EE325FC100112EF2E123.56AC29295781342F53AB242D03EE33'