Objective
After we use the automation post, want to proceed to this post operation, then need to use parameters associated with, Post will have a post ID, get to this ID, continue to pass this post ID can be
First, delete the draft box
1. We have previously told you to save the draft box after logging in, then you can continue to do: Delete the draft you just saved
2. Grab the bag with fiddler, catch the request to delete the post, from the packet capture results can be seen, the JSON parameter is PostID
3. Where does this postid come from? Can look at the last Request URL address
4. In other words, after the success of saving the draft box, redirect a URL address with the PostID parameter. Then we're going to pull it out.
Second, extracting parameters
1. We need the parameter PostID is the URL address after the successful save, this time from the URL address of the corresponding parameter value on the line, first get the URL after saving successfully
2. Extract the required string by regular, the parameter value before (postid=) and the Back (&) string are fixed
3. Here is the list type, the first value can be a string (note: Each save needs to modify the content, can not be repeated)
Third, the transfer of parameters
1. Delete the JSON parameter of the Drafts box to pass the parameters above: {"PostID": postid[0]}
2.json data type post with JSON on it, it automatically goes to JSON.
3. Then the previous Save draft box operation, you can delete the successful
Iv. Reference Code
# Coding:utf-8
Import requests
url = "Https://passport.cnblogs.com/user/signin"
headers = {"User-agent": "mozilla/5.0 (Windows NT 10.0; WOW64; rv:44.0) gecko/20100101 firefox/44.0 ",
"Accept": "Application/json, Text/javascript, */*; q=0.01 ",
"Accept-language": "zh-cn,zh;q=0.8,en-us;q=0.5,en;q=0.3",
"Accept-encoding": "gzip, deflate, BR",
"Content-type": "Application/json; Charset=utf-8 ",
"X-requested-with": "XMLHttpRequest",
"Content-length": "385",
"Cookie": "XXX has been omitted",
"Connection": "Keep-alive"
}
Payload = {
"INPUT1": "XXX",
"Input2": "XXX",
"Remember": True}
# First Step: Session Login
s = requests.session ()
r = S.post (URL, json=payload, headers=headers, Verify=false)
Print R.json ()
# Step Two: Save drafts
URL2 = "Https://i.cnblogs.com/EditPosts.aspx?opt=1"
BODY = {"__viewstate": "",
"__viewstategenerator": "fe27d343",
"Editor$edit$txbtitle": "This is my title: Shanghai-Leisurely",
"Editor$edit$editorbody": "<p> here is Chinese content:http://www.cnblogs.com/yoyoketang/</p>",
"Editor$edit$advanced$ckbpublished": "On",
"Editor$edit$advanced$chkdisplayhomepage": "On",
"Editor$edit$advanced$chkcomments": "On",
"Editor$edit$advanced$chkmainsyndication": "On",
"Editor$edit$lkbdraft": "Save as draft",
}
r2 = S.post (Url2, Data=body, Verify=false)
# Get the current URL address
Print R2.url
# Step Three: Regular extraction of required parameter values
Import re
PostID = Re.findall (r "postid= (. +?) & ", R2.url)
Print PostID # here is the list
# Extract As String
Print Postid[0]
# Fourth Step: Delete a draft box
Url3 = "Https://i.cnblogs.com/post/delete"
Json3 = {"PostID": postid[0]}
R3 = S.post (Url3, Json=json3, Verify=false)
Print R3.json ()
interested in Python interface automation, you can add Python interface Automation QQ Group: 226296743
You can also pay attention to my personal public number:
Python interface Automation 7-parameter correlation