Files
task-2-1-data-collection/蠕虫·.py
2026-03-16 22:13:33 +08:00

26 lines
590 B
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import requests
# 发送GET请求
response = requests.get('https://example.com')
# 查看响应状态码
print(response.status_code) # 200
# 查看响应内容(文本)
print(response.text)
# 查看响应内容JSON
print(response.json())
# 查看响应头
print(response.headers)
import requests
url = 'https: //example.com'
params = {'key': 'value'}
response = requests.get(url, params=params)
if response.status_code == 200:
html_content = response.text
print("请求成功,获取到HTML内容")
else:
print(f"请求失败,状态码: {response.status_code}")