http://www.yuyong.net

细说requests 使用教程

电脑现已成为我们工作、生活和娱乐必不可少的工具了,在使用电脑的过程中,可能会遇到requests 使用教程的问题,如果我们遇到了requests 使用教程的情况,该怎么处理怎么才能解决...

电脑现已成为我们工作、生活和娱乐必不可少的工具了,在使用电脑的过程中,可能会遇到requests 使用教程的问题,如果我们遇到了requests 使用教程的情况,该怎么处理怎么才能解决requests 使用教程带来的困扰呢,对于这样的问题其实我们只需要python3本文以sublime text3作为示范,创建一个python文档。import requests首先我们必须要引入模块,并且查看是否有报错。import requestshtml = requests.get(网页)我们经常用的获取一个网页,就是用get方法。print(html)这个时候直接打印就会返回相应值,200证明就是能够访问网页。print(html.url)如果需要再确这样就解决了这样的问题,接下来给大家带来requests 使用教程的详细操作步骤。

工具/原料

python3

方法/步骤

本文以sublime text3作为示范,创建一个python文档。

细说requests 使用教程

import requests

首先我们必须要引入模块,并且查看是否有报错。

细说requests 使用教程

import requests

html = requests.get(网页)

我们经常用的获取一个网页,就是用get方法。

细说requests 使用教程

print(html)

这个时候直接打印就会返回相应值,200证明就是能够访问网页。

细说requests 使用教程

print(html.url)

如果需要再确定网页的地址,可以用url来查看。

细说requests 使用教程

print(html.content)

如果要查看内容,可以用content来查询。但是这里是乱码。

细说requests 使用教程

print(html.encoding)

那么我们可以查看编码,原来这里是ISO-8859-1。

细说requests 使用教程

html.encoding = 'utf-8'

print(html.text)

这个时候转换一下编码,就会发现没有出错。text也是可以获取内容的。

细说requests 使用教程

注意事项

注意是requests,而不是request

郑重声明:本文版权归原作者所有,转载文章仅为传播更多信息之目的,如作者信息标记有误,请第一时间联系我们修改或删除,多谢。