[原]Python爬虫编程思想(20):requests网络库的基本用法
2021-09-08 09:12:57 Author: blog.csdn.net(查看原文) 阅读量:53 收藏

目录

1. requests的HelloWorld

2. GET请求

3  添加HTTP请求头


1. requests的HelloWorld

学习任何一种技术,都会用一个超级简单的案例起步,这个案例统称为HelloWorld。学习requests我们也沿用这个习惯。

在开始使用requests之前,需要使用下面的命令安装requests。

pip install requests

urllib库中的urlopen方法实际上是以GET方式请求网页,而requests中对应的方法是get,该方法可以接收一个URL,然后会返回一个对象,通过get方法的返回值,可以获取HTTP响应数据。

下面的例子使用get方法访问淘宝首页(https://www.taobao.com&#


文章来源: https://blog.csdn.net/nokiaguy/article/details/120171135
如有侵权请联系:admin#unsafe.sh