Requests is a lightweight http client library of python, which is much more elegant than the standard library of python. Next, this article will introduce you to Python3's method of sending flash memory via requests. If you are interested, learn it together. requests is a lightweight http client library of python, which is much more elegant than the standard library of python. Next, we will use this article to introduce how to use requests to send flash memory to Python3. Let's learn it together.
Run the following command to install requests:
The Code is as follows:
Pip install requests
The packet capture tool contains many http headers and cookies, some of which can be omitted. For example, Content-Length is omitted.
Import requestsurl = 'HTTP: // plain, text/javascript, */*; q = 0.01 ', 'origin': 'http: // ing.cnblogs.com ', 'X-Requested-with': 'xmlhttprequest ', 'content-type': 'application/json; charset = UTF-8', 'dnt ': 1, 'Referer ': 'http: // ing.cnblogs.com/', 'accept-encoding':'gzip, deflate ', 'Accept-color': 'zh-CN, zh; q = 0.8, en; q = 100 ',} # The session can be obtained through the packet capture tool or cookies tool. cookies = {'. CNBlogsCookie ': '201783c410c2b815a833d5816ceb5b457b159a38f'} # Your _ blank fill in your own sessiondata = {"content": "[stars in the sky do not speak] python syntax {}", "publicFlag": 1} s = requests. session () for r in range (1,122): data ['content'] = "[stars in the sky do not speak] python syntax {}". format (r) post = s. post (url, data, cookies = cookies) print (post. text)
Run the following code to delete the flash memory:
Import requestsimport redef timeit (fn): import timedef v (): start = time. clock () fn () end = time. clock ()-startprint (fn. _ name __, "running time:", end) return vurl =' http://ing.cnblogs.com /Ajax/ing/GetIngList? IngListType = my & PageIndex = 1 & PageSize = 30 'head = {'access': 'application/json, text/javascript, */*; q = 100 ', 'origin ':' http://ing.cnblogs.com ', 'X-Requested-with': 'xmlhttprequest', 'content-type': 'application/json; charset = UTF-8 ', 'dnt': 1, 'Referer ':' http://ing.cnblogs.com /Mobile/', 'Accept-encoding': 'gzip, deflate', 'Accept-color': 'zh-CN, zh; q = 0.8, en; q = 0.6 ',} cookies = {'. CNBlogsCookie ': 'authorization'} s = requests. session () @ timeitdef geting (): data = {'ingid': '000000'} r = s. get (url, cookies = cookies) text = r. textingid = re. findall (''' feed _ content _ (\ d + )(. +? The stars in the sky do not speak. +? DelIng) ''', text, re. DOTALL) # ingid = re. findall ('''feed _ content _ (\ d +) ''', text) # print (ingid) notlucky = [a for, B in ingid if 'ing _ icon_lucky 'not in B] for x in notlucky: data ['ingid'] = xtry: sdel = s. post (" http://ing.cnblogs.com /Ajax/ing/del ", cookies = cookies, data = data) print (sdel. text) before T: passfor xxx in range (18): geting ()