当前位置:首页 > 实验代码 > 正文内容

python网络请求:发送GET请求并获取响应内容

千帆5个月前 (12-24)实验代码1190

import requests


url = "http://tzshw.com"  # 替换为你的URL

response = requests.get(url)


# 假设服务器返回的是UTF-8编码,如果不是,需要替换为正确的编码


content = response.content.decode('utf-8')

print(content)



以下对中文显示为乱码:

import requests

url = 'http://tzshw.com'

response = requests.get(url)

print(response.text)



扫描二维码推送至手机访问。

版权声明:本文由千帆生活网发布,如需转载请注明出处。

本文链接:http://ntshw.com/?id=183

分享给朋友:

“python网络请求:发送GET请求并获取响应内容” 的相关文章

文本框只允许输入数字的控制方法

onKeyUp="if(isNaN(value))execCommand('undo')" onafterpaste="if(isNaN(value))execCommand('undo')"在输入小数字点时,也会自动分析判断,...

Python代码打包成exe文件

要将Python代码打包成exe文件,可以使用PyInstaller工具。以下是使用PyInstaller打包Python脚本为exe文件的步骤:安装PyInstaller:pip install pyinstaller使用PyInstaller打包Python脚本:pyinstaller --on...

python文本处理:统计文本中单词出现的频率

text = "This is a sample text for word frequency analysis."words = text.split()word_count = {}for word in words:    if word in wor...

python文件操作:复制文件

import shutilsrc_file = 'source.txt'dest_file = 'destination.txt'shutil.copyfile(src_file, dest_file)...