python3使用requests发闪存的方法

requests是一个python 轻量的http客户端库,相比python的标准库要优雅很多。接下来通过本文给大家介绍python3使用requests发闪存的方法,一起学习吧。

使用以下命令安装requests

代码如下:

pip install requests

抓包工具中看到的http头和cookies会多很多项,其中一些是可以省略掉的。比如我省略掉了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)

以下代码用于删除闪存

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
ing”feed_content_(\d+)(.+?天上的星星不说话.+?deling)”’,text,re.dotall)
#ing”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()

Posted in 未分类