Home > Backend Development > Python Tutorial > python采用requests库模拟登录和抓取数据的简单示例

python采用requests库模拟登录和抓取数据的简单示例

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-16 08:43:27
Original
1396 people have browsed it

如果你还在为python的各种urllib和urlibs,cookielib 头疼,或者还还在为python模拟登录和抓取数据而抓狂,那么来看看我们推荐的requests,python采集数据模拟登录必备利器!

这也是python推荐的HTTP客户端库:

本文就以一个模拟登录的例子来加以说明,至于采集大家就请自行发挥吧。

代码很简单,主要是展现python的requests库的简单至极,代码如下:

s = requests.session()
data = {'user':'用户名','passdw':'密码'}
#post 换成登录的地址,
res=s.post('http://www.xxx.net/index.php?action=login',data);
#换成抓取的地址
s.get('http://www.xxx.net/archives/155/');

Copy after login

看!仅仅4行代码,即可模拟登录。

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template