python发送http的get请求
时间: 2023-09-02 07:13:03 浏览: 174
可以使用Python的requests库来发送HTTP的GET请求。
首先,需要安装requests库,可以使用以下命令在命令行中安装:
```
pip install requests
```
然后,可以使用以下代码发送GET请求:
```python
import requests
url = "http://www.example.com/api/get_data"
response = requests.get(url)
print(response.text)
```
在上面的代码中,我们首先定义了请求的URL,然后使用requests库的get()方法发送GET请求。最后,我们打印出响应的内容。
如果需要传递参数,可以在URL中添加查询参数,例如:
```python
import requests
url = "http://www.example.com/api/get_data"
params = {"param1": "value1", "param2": "value2"}
response = requests.get(url, params=params)
print(response.text)
```
在上面的代码中,我们在URL中添加了查询参数param1和param2,并将参数传递给get()方法。
阅读全文
相关推荐









