search
HomeBackend DevelopmentPython TutorialPython3 uses requests to send flash memory

requests is a python lightweight http client library, which is much more elegant than python's standard library. Next, through this article, I will introduce to you how Python3 uses requests to send flash memory. Friends who are interested can learn together.

requests is a python lightweight http client library, which is much more elegant than the python standard library. Next, through this article, I will introduce to you how to use requests to send flash memory in Python3. Let’s learn together.

Use the following command to install requests


##Copy code The code is as follows:

pip install requests

There will be many more http headers and cookies seen in the packet capture tool, some of which can be omitted. For example, I omitted Content-Length.

import requests
url='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 通过抓包工具,或者cookies工具可以得到.
cookies={'.CNBlogsCookie':'67834BD16E61A87726AF2203F849339E8DEFF67BC4A453FDG830AC373CAC83BAAF2312B975279092095A0E143400E82BBEE189BD5CB8826CA6A6E836F69EC5783C410C2B815A833D5816CEB5B457B159A38F'}#←_←填你自己的session
data={"content":"[天上的星星不说话]python大法好{}","publicFlag":1}
s=requests.Session()
for r in range(1,122):
data['content']="[天上的星星不说话]python大法好{}".format(r)
post=s.post(url,data,cookies=cookies)
print(post.text)

The following code is used to delete flash memory

import requests
import re
def timeit(fn):
import time
def v():
start=time.clock()
fn()
end=time.clock()-start
print(fn.__name__,"运行耗时:",end)
return v
url='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()
@timeit
def geting():
data={'ingId':'878581'}
r=s.get(url,cookies=cookies)
text=r.text
ingid=re.findall('''feed_content_(\d+)(.+?天上的星星不说话.+?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']=x
try:
sdel=s.post("http://ing.cnblogs.com/ajax/ing/del",cookies=cookies,data=data)
print(sdel.text)
except:
pass
for xxx in range(18):
geting()



For more articles related to Python3 using requests to send flash memory, please pay attention to the PHP Chinese website!


Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Python's Hybrid Approach: Compilation and Interpretation CombinedPython's Hybrid Approach: Compilation and Interpretation CombinedMay 08, 2025 am 12:16 AM

Pythonusesahybridapproach,combiningcompilationtobytecodeandinterpretation.1)Codeiscompiledtoplatform-independentbytecode.2)BytecodeisinterpretedbythePythonVirtualMachine,enhancingefficiencyandportability.

Learn the Differences Between Python's 'for' and 'while' LoopsLearn the Differences Between Python's 'for' and 'while' LoopsMay 08, 2025 am 12:11 AM

ThekeydifferencesbetweenPython's"for"and"while"loopsare:1)"For"loopsareidealforiteratingoversequencesorknowniterations,while2)"while"loopsarebetterforcontinuinguntilaconditionismetwithoutpredefinediterations.Un

Python concatenate lists with duplicatesPython concatenate lists with duplicatesMay 08, 2025 am 12:09 AM

In Python, you can connect lists and manage duplicate elements through a variety of methods: 1) Use operators or extend() to retain all duplicate elements; 2) Convert to sets and then return to lists to remove all duplicate elements, but the original order will be lost; 3) Use loops or list comprehensions to combine sets to remove duplicate elements and maintain the original order.

Python List Concatenation Performance: Speed ComparisonPython List Concatenation Performance: Speed ComparisonMay 08, 2025 am 12:09 AM

ThefastestmethodforlistconcatenationinPythondependsonlistsize:1)Forsmalllists,the operatorisefficient.2)Forlargerlists,list.extend()orlistcomprehensionisfaster,withextend()beingmorememory-efficientbymodifyinglistsin-place.

How do you insert elements into a Python list?How do you insert elements into a Python list?May 08, 2025 am 12:07 AM

ToinsertelementsintoaPythonlist,useappend()toaddtotheend,insert()foraspecificposition,andextend()formultipleelements.1)Useappend()foraddingsingleitemstotheend.2)Useinsert()toaddataspecificindex,thoughit'sslowerforlargelists.3)Useextend()toaddmultiple

Are Python lists dynamic arrays or linked lists under the hood?Are Python lists dynamic arrays or linked lists under the hood?May 07, 2025 am 12:16 AM

Pythonlistsareimplementedasdynamicarrays,notlinkedlists.1)Theyarestoredincontiguousmemoryblocks,whichmayrequirereallocationwhenappendingitems,impactingperformance.2)Linkedlistswouldofferefficientinsertions/deletionsbutslowerindexedaccess,leadingPytho

How do you remove elements from a Python list?How do you remove elements from a Python list?May 07, 2025 am 12:15 AM

Pythonoffersfourmainmethodstoremoveelementsfromalist:1)remove(value)removesthefirstoccurrenceofavalue,2)pop(index)removesandreturnsanelementataspecifiedindex,3)delstatementremoveselementsbyindexorslice,and4)clear()removesallitemsfromthelist.Eachmetho

What should you check if you get a 'Permission denied' error when trying to run a script?What should you check if you get a 'Permission denied' error when trying to run a script?May 07, 2025 am 12:12 AM

Toresolvea"Permissiondenied"errorwhenrunningascript,followthesesteps:1)Checkandadjustthescript'spermissionsusingchmod xmyscript.shtomakeitexecutable.2)Ensurethescriptislocatedinadirectorywhereyouhavewritepermissions,suchasyourhomedirectory.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.