synopsis
Everyone on the front of the automation of the new task after the next to understand this new task operation, I hope to bring small partners to further consolidate the fruits of victory, solid foundation. Therefore, again in the sand example walkthrough of the relevant interface of the blog garden. After we use automation to send an essay, to then operate on this essay, it goes without saying that it needs to be
To use the parameter association, after posting an essay, there will be an essay id, get this id, continue to operate to pass this essay id can be (blog garden login mechanism has changed, can not use the account number and password login, here with a cookie login)
Roughly process steps: web interface operation login capture packet view cookie -> code simulation cookie login -> web interface operation new pen and save pen -> capture packet view new pen and save pen url and parameters, etc. ->Code simulation to create a new pen and save the edited content ->Web interface operation to delete the pen ->Grab the delete operation request ->Extract parameters ->Pass parameters ->Code implementation.
I. Deletion of the accompanying text
1, we spoke earlier about logging in after the new pen and save the pen, do not remember to click on theportalThen you can go on to the next step: delete the new pen you just created.
2, with fiddler capture packet, capture the request to delete the new pen, from the capture results can be seen, the passed json parameters are postId
3. Where does this postId come from? You can see the url address of the last request.
4, that is to say, after the success of saving the draft box, redirected to a url address, which carries the postId parameter. Then we find a way to extract this parameter can be
II. Extraction parameters
1, we need the parameter postId is saved after the success of the url address, this time from the url address of the corresponding parameter value on the line, the first to get saved after the success of the url
2, through the regular expression from the saved url to extract the required string, the value of this parameter in front of (postid =) and after (&) the string is fixed
3, here the regular proposed list type, take the first value can be a string (note: each save need to modify the content, can not be repeated)
III. Transmission of references
1, delete the json parameter of the draft box pass the parameter fetched above: {"postId": postid[0]}
2, json data type post fill in json on the line, will automatically turn json
3, followed by the previous operation to save the pen, you can delete the success of the
Note: the same reason and jenkins, if you want to see clearly, you can delete the new follower out of the interruption point, see the new follower, and then execute the following code to see if it is possible to delete the new follower
IV. Reference codes
# coding:utf-8 import requests # Open the login home page first to get a partial cookie url = "/user/signin" headers = { "User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64; rv:44.0) Gecko/20100101 Firefox/44.0" } # get method other than ser-agent can be added s = () r = (url, headers=headers,verify=False) print () # Add the two cookies required for login c = () ('.CNBlogsCookie', 'XXX') # Fill in the catch above ('.','XXX') # Fill in the catch above ('AlwaysCreateItemsAsActive',"True") ('AdminCookieAlwaysExpandAdvanced',"True") (c) print () # Save edits after successful login url2= "/?opt=1" body = {"__VIEWSTATE": "", "__VIEWSTATEGENERATOR":"FE27D343", "Editor$Edit$txbTitle":"This is the title of the bypass login:Beijing, capital of People's *-* businessman", "Editor$Edit$EditorBody":"<p>Here is the Chinese content:/duhong/</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 = (url2, data=body, verify=False) #print (('utf-8')) # Step 3: Regularly extract the required parameter values import re postid = (r"postid=(.+?)&", ) print(type(postid)) print (postid) # Here's the list # Extract to string print (postid[0]) # Step 4: Delete the draft box url3 = "/post/delete" json3 = {"postId": postid[0]} r3 = (url3, json=json3, verify=False) print (())
V. Summary
1, well, the parameters associated with the interface is so simple, I believe that all partners next time encounter this kind of similar problems, will not panic, it should be nine out of ten KO off.
2, interested in their own can be the same as the previous article, their own practice interrupt point, they can experience the fun and magic.
The above is a small introduction to the python interface automation parameters associated with the interface detailed integration, I hope to help you, if you have any questions please leave me a message, I will reply to you in time. I would also like to thank you very much for your support of my website!