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

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

千帆11个月前 (12-24)实验代码2466

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://513qh.com/?id=183

分享给朋友:

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

修改sql数据库名称

EXEC sp_dboption 'OldDbName', 'Single User', 'TRUE' EXEC sp_renamedb 'OldDbName', 'NewDbName' EXEC s...

Python输出指定范围内的素数

# 输出指定范围内的素数# take input from the userlower = int(input("输入区间最小值: "))upper = int(input("输入区间最大值: "))for num in range(lower,upper +...

Python计算每个月天数

import calendar'''输出的是一个元组,第一个元素是所查月份的第一天对应的是星期几(0-6),第二个元素是这个月的天数。以上实例输出的意思为 2016 年 9 月份的第一天是星期四,该月总共有 30 天。'''monthRange = c...

Python清空列表

RUNOOB = [6, 0, 4, 1]print('清空前:', RUNOOB)RUNOOB.clear()print('清空后:', RUNOOB)'''以上实例输出结果为:清空前: [6, 0, 4, 1]清空后: []'...

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)...