能夠經過dict[key]得到dict[value]

 

dict={key:value,key2:value2}web

print (dict[key] )    獲得的是 dict[value]json

# 軟文預存接口,經過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) # 原本想把換行\n寫在這裏的,可是pprint不支持
            print('\n')
            # 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
相關文章
相關標籤/搜索