美文网首页
python的web请求(requests的用法)

python的web请求(requests的用法)

作者: 不懒狮Blaise | 来源:发表于2018-02-09 15:01 被阅读0次
    import json
    import gzip
    import urllib
    import urllib2
    import time
    import requests
    
    # ip和模块是容易改动的
    URL = "http://127.0.0.1:5000/add_article"
    PARAMS = {'uid':1, "head": "head111", "content":"content222"}
    
    def post_form(url, params, method="post"):
        url = URL + url
        params = dict(PARAMS, **params)
        if method == "get":
            data = urllib.urlencode(params)
            url = url+ '?' +data
            print url
            req = urllib2.Request(url)
            r = urllib2.urlopen(req)
        else:
            print url, params
            data = urllib.urlencode(params)
            req = urllib2.Request(url)
            r = urllib2.urlopen(req, data)
            
        print r.text
    
    params = {'account': 3}
    post_form('', params, 'post')
    
    
    

    相关文章

      网友评论

          本文标题:python的web请求(requests的用法)

          本文链接:https://www.haomeiwen.com/subject/jwgftftx.html