首页 > IT职业 > IT图书 > python查询字符串参数

1、说明
自定义GET请求的一种常用方法是通过URL中的 查询字符串参数传递值。 要使用 get() 执行此操作,请将数据传递给 params。
查询字符串对于参数化GET请求很有用。 还可以通过添加或修改发送的请求的头部来自定义你的请求。
2、实例
可以使用GitHub的Search API来查找 requests 库:
import requests
# Search GitHub's repositories for requests
response = requests.get(
'https://api.github.com/search/repositories',
params={'q': 'requests+language:python'},
)
# Inspect some attributes of the `requests` repository
json_response = response.json()
repository = json_response['items'][0]
print(f'Repository name: {repository["name"]}') # Python 3.6+
print(f'Repository description: {repository["description"]}') # Python 3.6+
以上就是python查询字符串参数的方法,希望对大家有所帮助。更多Python学习指路:python基础教程
本文教程操作环境:windows7系统、Python 3.9.1,DELL G3电脑。
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/201/viewspace-2830364/ ,如需转载,请注明出处,否则将追究法律责任。