python request xml

问题
对于ajax请求,很多人无从下手,包括用python 实现其请求。
办法
其实第一步是分析本页面调用js。可以通过chrome去F12查看。找到需要请求的代码。例如登陆login.js
然后使用ctrl+F查找ajax。可以看到请求方式post或者get。甚至大家可以chrome在线调试js。观看其提交数据。
python
get_ajax.py

import requests
ajax_url=''
header={}#有些认证是通过header添加自定义字段,没有特殊可以不加
r = requests.get(ajax_url, headers=headers,timeout=3)
        print str(r.status_code) + '---',
        content = r.text
        r.close()
        #print content
        if content.find('200') == -1:
            print "NO!"
        else:
            print "YES!"

post_ajax.py

import requests
ajax_url=''
header={}#有些认证是通过header添加自定义字段,没有特殊可以不加
data=''
r = requests.post(ajax_url, headers=headers,data=data,timeout=3)
        print str(r.status_code) + '---',
        content = r.text
        r.close()
        #print content
        if content.find('200') == -1:
            print "NO!"
        else:
            print "YES!"

猜你喜欢

转载自blog.csdn.net/DAo_1990/article/details/70145526