4

Python爬虫编程思想(25):使用requests实现身份验证和请求打包

 2 years ago
source link: https://blog.csdn.net/nokiaguy/article/details/120304233
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

目录

1. 身份验证

2. 将请求打包


1. 身份验证

        使用urllib库进行身份验证时,需要使用一大堆类,如HTTPPasswordMgrWithDefaultRealm、HTTPBasicAuthHandler等,非常麻烦。使用requests进行身份验证就简单得多,只需要设置auth参数即可。auth参数的值是一个HTTPBasicAuth对象,封装了用户名和密码。

下面的例子向服务端发送支持Basic验证的请求,如果验证成功,服务端会返回success。


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK