以下是使用 Python 中的 requests 库发送请求并获取网页数据的示例代码:

import requests

url = 'https://www.example.com'
response = requests.get(url)

print(response.text)  # 输出网页内容

解释:

  1. 导入 requests 库
  2. 定义 URL 变量
  3. 使用 requests.get() 方法发送 HTTP GET 请求,并将响应保存在 response 变量中
  4. 使用 response.text 属性获取响应的文本内容,并打印输出
Python 网络爬虫:使用 requests 库发送请求获取网页数据

原文地址: https://www.cveoy.top/t/topic/oA5P 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录