如何使用python urllib2发送json数据进行登录 [英] How to use python urllib2 to send json data for login

查看:587
本文介绍了如何使用python urllib2发送json数据进行登录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用python urllib2模拟登录操作,我使用Fiddler捕获数据包,并获得登录操作只是ajax请求,而用户名和密码作为json数据发送,但是我不知道如何使用urllib2发送json数据,帮助...

I want to use python urllib2 to simulate a login action, I use Fiddler to catch the packets and got that the login action is just an ajax request and the username and password is sent as json data, but I have no idea how to use urllib2 to send json data, help...

推荐答案

import urllib2
import json
# Whatever structure you need to send goes here:
jdata = json.dumps({"username":"...", "password":"..."})
urllib2.urlopen("http://www.example.com/", jdata)

这假设您正在使用HTTP POST发送带有用户名和密码的简单json对象.

This assumes you're using HTTP POST to send a simple json object with username and password.

这篇关于如何使用python urllib2发送json数据进行登录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆