可以通过dict[key]获得dict[value]

dict={key:value,key2:value2}

print (dict[key] )    得到的是 dict[value]

# 软文预存接口,通过key来预览未保存的软文,联查商品、kol详情,已保存的软文需要调用查看接口
presaveUlr = 'http://www.cmall.com/topicSocSite/article/presaveArticle'
presaveData = {"clientType":"web", "abbr":"cn", "titleCn":"哈向上雇主", "cover":"imageView2/2/w/270/q/90", "general":"哎哟嗨哎哟嗨押尾", "articleTags":"[{'tagName':'潮品', 'operation':3}]", "articleContents":"[{'id':995, 'contentType':1, 'contentText':'试试改变一下update', 'display':1}]"}

# 软文预览接口
previewUrl = 'http://www.cmall.com/topicSocSite/article/previewArticle'
previewData = {"clientType":"web", "abbr":"cn"}




# 将请求参数都写在list中
interface_list_post = [{getlistUrl:getlistData}, {saveArticleUrl:saveArticleData},
                  {saveArticleUrl:saveArticleDataUpdate},{queryArticleUrl:queryArticleData},
                  {addViewUrl:addViewData}, {recommendUrl:recommendData},{likeUrl:likeData},
                  {recentTagUlr:recentTagData}, {getcountUrl:getcountData}, {saveReportUrl:saveReportData},
                  {reportTypeUrl:reportTypeData}, {deletArticleUrl:deletArticleData},{presaveUlr:previewData},
                  {previewUrl:previewData}]

dict = {presaveUlr:previewUrl}
dict1={}

interface_list_get = [{recentTagUlr:recentTagData}]

# 主题函数,带data请求url,主要post方式
def article_in_post(url,data):
    articleRequest = requests.post(url=url, data=data, cookies=modeltry1109.mylogin())
    # print(articleRequest.url)
    artjson = articleRequest.json()
    # pprint(artjson)to
    if articleRequest.status_code == 200:  # 如果请求状态200,则判断返回code
        if artjson['code'] == '200':       # 返回code==200,则通过,并展示response的json格式
            print('PASS+PSS+PASS:'+ articleRequest.url)
            # pprint(artjson) # 本来想把换行
写在这里的,但是pprint不支持
            print('
')
            # if artjson['result'] is exit:
            '''这一段用来处理匹配token,重新来一次带token的请求,但不确定是否正确'''
            a = dict.get(url, 'not find')  # 判断url是否存在于dict的key值中
            if a != 'not find':
                token = artjson['result']
                dict1[dict[url]]= token
                print(dict1)
                print(dict[url])
                for xxx in interface_list_post:
                    aaa = xxx.get(dict[url], 'not find')
                    if aaa != 'not find':
                        print(xxx[dict[url]])  # xxx是 list中的一对一对,dict[url]是获取dict中的需要得到token的url,xxx[dict[url]]是一对中的value,
                                               # 也就是需要得到token的ulr对应的data
                        print(token)
                        xxx[dict[url]]['key']=token   # 需要得到token的url对应的data中 添加 key:token
                        print(xxx) # 打印出list中的这对正在操作的xxx:url:data
原文地址:https://www.cnblogs.com/vivivi/p/6089251.html