Python3 uses requests to send flash memory, python3requests
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:
Copy codeThe 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 __, "Run 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 ': '989a8f9sf9sf9425982938 Required '} 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) rows T: passfor xxx in range (18): geting ()