1 #-*-coding:utf-8-*-2 __author__="Carry"3 ImportRequests4 ImportRe5 #Disable security Request warning6 fromRequests.packages.urllib3.exceptionsImportinsecurerequestwarning7 requests.packages.urllib3.disable_warnings (insecurerequestwarning)8 9s =requests.session ()Ten One " "First Interface--------------login interface" " AURL1 ="Https://passport.cnblogs.com/user/signin" -Header = {#headers here. - "user-agent":"mozilla/5.0 (Windows NT 6.1; WOW64; rv:46.0) gecko/20100101 firefox/46.0", the "accept-encoding":"gzip, deflate, BR", - "Accept-language":"zh-cn,zh;q=0.8,en-us;q=0.5,en;q=0.3", - "X-requested-with":"XMLHttpRequest", - "Content-type":"Application/json; Charset=utf-8", + "Cookies":"aspxautodetectcookiesupport=1; serverid=227b087667da6f8e99a1165002db93f6|1505215478|1505215339" - } +Json_data1 = {"INPUT1":"b45eea7p/zb2jqjo+ihkz7fevdxts380b5w8atgo1f6uiw7icjmj1yfmfzfnq1c2qsp0bocptbgvt8arrs/e6kpc9/ jccd6fzxajjxwz0sf3hxos08yipa9knshl6ik+3jwemykcfrmcvf6j2vo=", A "Input2":"x4bkpbfodguamtplmz/hoqau7nsf1kfyxhinheak49gjmu0ftglbzg6qlv/nqrh2pi+ Lkwmqr513h6ktz4ela8thtcxlfs9nvkmkpcn91mqjs29v3fqwpbtvwmrvyn9getfdjlkqshb7tper57bvrde=", at "Remember": False} -Res1 = S.post (URL1, Headers=header, Json=json_data1, verify=False) - Print(Res1.json ()) - - " "second interface--------------saved as a draft interface" " -URL2 ="https://i.cnblogs.com/EditPosts.aspx?opt=1" inJson_data2 = {"__viewstate":"", - "__viewstategenerator":"fe27d343", to "Editor$edit$txbtitle":"I'm the killer number 2nd .", + "Editor$edit$editorbody":"<p>%s</p>"%"I'm the killer number 2nd .", - "editor$edit$advanced$ckbpublished":" on", the "Editor$edit$advanced$chkdisplayhomepage":" on", * "editor$edit$advanced$chkcomments":" on", $ "editor$edit$advanced$chkmainsyndication":" on",Panax Notoginseng "Editor$edit$lkbdraft":"Save as draft", } -Res2 = S.post (Url2, Data=json_data2, verify=False) the Print(Res2.url) + " "This place is extracting postid, using regular expressions" " APostID = Re.findall (r"postid= (. +?) &", Res2.url) the Print(PostID) + Print(postid[0]) - $ " "Third Interface--------------Delete Draft interface" " $Json_data3 = {"PostID": postid[0]} -R3 ="Https://i.cnblogs.com/post/delete" -Res3 = S.post (R3, JSON=JSON_DATA3, verify=False) the Print(Res3.json () ["issuccess"])
Python requests Interface Test-----Blog Cluster interface