python Python的几种HTTP GET方法

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python Python的几种HTTP GET方法相关的知识,希望对你有一定的参考价值。

# 方法一:Python 2.x:
import urllib2
contents = urllib2.urlopen("http://example.com/foo/bar").read()

# 方法二:Python 3.x:
import urllib.request
contents = urllib.request.urlopen("http://example.com/foo/bar").read()

# 方法三:需要安装requests
import requests
r = requests.get("http://example.com/foo/bar")
print(r.status_code)
print(r.headers)
print(r.content)


# 来源:https://stackoverflow.com/questions/645312/what-is-the-quickest-way-to-http-get-in-python

以上是关于python Python的几种HTTP GET方法的主要内容,如果未能解决你的问题,请参考以下文章

Python 获取环境变量的几种方式

python操作数据库的几种方式

python爬虫多次请求超时的几种重试方法

python爬虫多次请求超时的几种重试方法

python 模块调用的几种方式

Python 逗号的几种作用