import httplib
import re
import time
if __name__=='__main__':
content=open('content.txt','r').read()
num=int(open('num.txt','r').read())
dingnum=0
l=content.split('endendend')
UserAgent="Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.110 Safari/537.36"
ContentType="application/x-www-form-urlencoded"
Host="bbs.ichunqiu.com"
ContentLength="151"
Accept="text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8"
Origin="http://bbs.ichunqiu.com"
matchpath="path:([^~]*)"
matchcookie="cookie:([^~]*)"
matchdata="data:([^~]*)"
starttime=time.time()
print("共顶%d个帖子" % len(l))
# l 帖子组
# c 单个帖子信息
for n in range(num):
n=n+1
print("正在进行第%d次" % n)
print "帖子组信息",l
for c in l:
try:
print ("具体信息:")
path=re.findall(matchpath,c)[0]
cookie=re.findall(matchcookie,c)[0]
data=re.findall(matchdata,c)[0]
print path
print cookie
print data
except:
print(c)
continue
conn=httplib.HTTPConnection('bbs.ichunqiu.com')
conn.request("POST",path,data,{"Host":Host,"Accept":Accept,"Origin":Origin,"User-Agent":UserAgent,"Content-Type":ContentType,"Cookie":cookie,
"Content-Length":ContentLength})
print "连接成功,等待服务器响应"
response=conn.getresponse()
content=response.read()
conn.close()
print "服务器响应如下:"
print(content.decode("utf-8"))
dingnum+=1
time.sleep(15.1)
endtime=time.time()
print("顶贴完成,共顶%d次 耗时:%d秒" % (dingnum,(endtime-starttime)) )