Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/331.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
python中带有URLPASSE的正则表达式_Python_Regex_Python 2.7_Preg Match_Urlparse - Fatal编程技术网

python中带有URLPASSE的正则表达式

python中带有URLPASSE的正则表达式,python,regex,python-2.7,preg-match,urlparse,Python,Regex,Python 2.7,Preg Match,Urlparse,我有这个网址: https://www.yoursite.com/drive/team-real-431/pepe-ozil-R323/anyway-jim-james-hi-bye-hi-321312/;jsessionid=DBDE454034B0EE325FC100112EF2E123.56AC29295781342F53AB242D03EE33 我想要 DBDE454034B0EE325FC100112EF2E123.56AC29295781342F53AB242D03EE33 我试

我有这个网址:

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

我使用Python2.7时,出现了以下错误:jsessionid=dict(urlparse.parse_qsl(url_parts.params)).get('jsessionid')NameError:name'url_parts'不是defined@Francesco谢谢,我编辑了我的问题,以便更好地使用
urlparse.parseqsl
,以防您有
jsessionid
以外的其他参数。
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'