Python3 uses requests to issue flash memory

Source: Internet
Author: User
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: // ', 'X-Requested-with': 'xmlhttprequest ', 'content-type': 'application/json; charset = UTF-8', 'dnt ': 1, 'Referer ': 'http: //', '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 =' /Ajax/ing/GetIngList? IngListType = my & PageIndex = 1 & PageSize = 30 'head = {'access': 'application/json, text/javascript, */*; q = 100 ', 'origin ':' ', 'X-Requested-with': 'xmlhttprequest', 'content-type': 'application/json; charset = UTF-8 ', 'dnt': 1, 'Referer ':' /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 (" /Ajax/ing/del ", cookies = cookies, data = data) print (sdel. text) before T: passfor xxx in range (18): geting ()
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.