Gog*_*oga -3 python python-3.x
我有一个URL作为字符串:
urlString = https://play.com/details?id=blamore
Run Code Online (Sandbox Code Playgroud)
如何id从给定的字符串中获取参数?
在Python 3中执行此操作的正确方法是使用该urllib.parse模块.
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)
Run Code Online (Sandbox Code Playgroud)
产量
ParseResult(scheme='https', netloc='play.com', path='/details', params='', query='id=blamore', fragment='')
{'id': ['blamore']}
Run Code Online (Sandbox Code Playgroud)
字段名称ParseResult应该是不言自明的,但请参阅文档了解详细信息.
解析作为字符串参数给出的查询字符串(类型为application/x-www-form-urlencoded的数据).数据作为字典返回.字典键是唯一的查询变量名称,值是每个名称的值列表.
| 归档时间: |
|
| 查看次数: |
489 次 |
| 最近记录: |