Requests is a Python lightweight HTTP client library that is much more elegant than the Python standard library. Next through this article to introduce PYTHON3 use requests flash memory method, interested friends learn together
Requests is a Python lightweight HTTP client library that is much more elegant than the Python standard library. Next through this article to introduce the PYTHON3 use requests flash memory method, learn it together.
Install requests using the following command
Copy the Code code as follows:
PIP Install requests
There are many more items of HTTP headers and cookies seen in the grab kit, some of which can be omitted. For example, I omitted content-length.
Import requestsurl= ' http://ing.cnblogs.com/ajax/ing/Publish ' head={' Accept ': ' Application/json, 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-language ': ' zh-cn,zh;q=0.8,en;q=0.6 ',} #session can get. cookies={' by means of a grab bag tool or a cookie tool. Cnblogscookie ': ' 67834bd16e61a87726af2203f849339e8deff67bc4a453fdg830ac373cac83baaf2312b975279092095a0e143400e82bbee189bd5cb8826ca6a6e836f 69ec5783c410c2b815a833d5816ceb5b457b159a38f '}#←_← fill your own sessiondata={"content": "[the stars in the sky Don't speak]python Dafa good {}", " Publicflag ": 1}s=requests. Session () for R in range (1,122):d ata[' content ']= ' [the stars in the sky Don't speak]python Dafa good {} '. Format (r) post=s.post (url,data,cookies= Cookies) print (Post.text)
The following code is used to remove flash
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={' Accept ': ' Application/json, 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/mobile/', ' accept-encoding ': ' gzip, deflate ', ' Accept-language ': ' zh-cn,zh;q=0.8,en;q=0.6 ',}cookies={'. Cnblogscookie ': ' 989a8f9sf9sf989s982938492849823498239489284989sdf89s89f8e98f9s88e9r89wer898r989r23423j4k2529r8fs7r2k48978s7df8 ' }s=requests. Session () @timeitdef geting ():d ata={' ingid ': ' 878581 '}r=s.get (url,cookies=cookies) text=r.textingid=re.findall ("' Feed_content_ (\d+) (. +) stars in the sky do not speak. +? deling) ", Text,re. Dotall) #ingid =re.findall ("Feed_content_ (\d+)", text) #print (ingid) notlucky=[a for A, 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) except:passfor xxx in range: geting ()