如何在Python中从字符串中提取id参数?

2024-09-30 04:38:08 发布

您现在位置:Python中文网/ 问答频道 /正文

我的URL为字符串:

urlString = https://play.com/details?id=blamore

如何从给定的字符串中获取id参数?在


Tags: 字符串httpscomidurlplay参数details
1条回答
网友
1楼 · 发布于 2024-09-30 04:38:08

在python3中正确的方法是使用^{}模块。在

from urllib.parse import urlparse, parse_qs 

url = 'https://play.com/details?id=blamore'

t = urlparse(url)
print(t)

d = parse_qs(t.query)
print(d)

输出

^{pr2}$

ParseResult的字段名应该是不言自明的,但是请参考the docs以获取详细信息。在

^{} docs

Parse a query string given as a string argument (data of type application/x-www-form-urlencoded). Data are returned as a dictionary. The dictionary keys are the unique query variable names and the values are lists of values for each name.

相关问题 更多 >

    热门问题