python request模板

# -*- coding: utf-8 -*-
import time
import requests


class Request:
    def __init__(self):
        self.s=requests.session()
    def get(self,url):
        r=self.s.get(url)
        #print r.content 返回html
        #print r.status_code 200
        #print r.headers['content-type'] text/html
        #print r.cookies['BDORZ']  27315
        #print r.cookies.get_dict()  {'BDORZ': '27315'}
        #s.cookies.update(r.cookies)  更新请求的cookie
    def post(self,url,data,cookie):
        r=self.s.post(url=url,data=data,cookies=cookie)
        print r.content


url='http://www.baidu.com'
obj=Request()
obj.get(url)

url2='http://cgi.find.qq.com/qqfind/buddy/search_v3'
obj=Request()

headers={
       'User-Agent': 'Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Mobile Safari/537.36'
}
d={
    'num':20,
    'page':0,
    'sessionid':0,
    'keyword':'',
    'agerg':0,
    'sex':0,
    'firston':1,
    'video':0,
    'country':1,
    'province':33,
    'city':3,
    'district':0,
    'hcountry':1,
    'hprovince':0,
    'hcity':1,
    'hdistrict':0,
    'online':1,
    'ldw':'2038029345',
}
c={
    "RK":"YPvyU0guth",
    "pgv_pvid":"9032603920",
    "pgv_pvi":"3328091136",
    "pgv_si":"s7733164032",
    "_qpsvr_localtk":"0.4076760951382583",
    "supertoken":"2476655395",
    "ptui_loginuin":"2327187519",
    "ptdrvs":"OZGsmFjh5SvU1Rw-cmQypUIeMDedKZdI3LLgQL8pYeM_",
    'ptvfsession':"1e7a1ec0745474ee7d8678f9f626c139b0b960585fd59c3d1c028cf7ceb0c6353d425e3aa881eecb456c73e3bc6e22da89193319e08e3bf4",
    'confirmuin':"0",
    'pt_recent_uins':"49aa5245e9655b1efcc113d2e1b3d9208f865022359f0de8b4b55fcfdf5c87e30e55a7197321a9d96ac017aa7a53e896e1432d34fd46c24a",
    'qrsig':"C0W34FzsAixQXQjTEekEiWAYU7cXJV5ksOIgct-sOq5xcZxVzCixQTi7tFaqhl0",
    'pt_guid_sig':"5788639c40d7afe81865952ccf6b43fb3d066a7d9835861eb64aac1b6d221eae",
    'uikey':'5e68cbfff02c4c42cd59e0d03856885176584aef1614958106fa54320ffa5c6f',
    'pt_local_token':'1587661985',
    'pt_serverip':'34cf0abf0659a9f9',
    'pt_login_sig':"TPE8hFWduS3r0TP5JTtEdjFn7bg3J1H3FA1IuOOFnex-I2nM3S6PkXl2uExZk4lP",
    'pt2gguin':'o2327187519',
    'supertoken':'2476655395'


}
obj.post(url2,data=d,cookie=c)

  

原文地址:https://www.cnblogs.com/norm/p/7486010.html