现在时间是:
当前位置:首 页 >> 数据采集>> 文章列表

Requests 利用Cookies对DZ论坛随意留言的注意事项

作者:   发布时间:2016-03-14 18:12:06   浏览次数:2231

利用Cookies单账号进行操作,因为回帖需要验证码,稍后再说。

这次仅仅针对打招呼和留言进行分析,捣腾了一阵子,结果发现在POST数据是所有涉及到ID的必须采用整型,这个要记住!



import requests
import myheader as md
import time
import random
# encoding: utf-8
__author__ = 'yeayee.com'
my_header = '''Host: www.yeayee.com
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:44.0) Gecko/20100101 Firefox/44.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3
Accept-Encoding: gzip, deflate
Referer: http://www.yeayee.com/home.php?mod=space&uid=1972&do=wall
Cookie: MbAx_2132_saltkey=kU1OFBfJ;
Connection: keep-alive'''
my_headerc = md.get_myheaderc(my_header)
# print(my_headerc)
base_url = 'http://www.yeayee.com/space-uid-1976.html'
s = requests.session()
nlp_txt = s.get(base_url,headers = my_headerc).text
# print(nlp_txt)
try: # 测试了半天,所有的post中的id必须是整型
for i in range(30):
time.sleep(random.uniform(1,2)) # 还是加上一个随机0-2秒的延迟比较妥当
id = str(random.randint(0,1975))
next_url = 'http://www.yeayee.com/space-uid-'+id+'.html'
if 'yeayee' in s.get(next_url).text:
print('YES')
# 招呼
post_url = 'http://www.yeayee.com/home.php?mod=spacecp&ac=poke&op=send&uid=' + id + '&inajax=1'
time.sleep(random.uniform(1,2))
zhao_data = {
'formhash':'34ddfce7',
'iconid':3,
'note':'good day',
'pokesubmit':'true'
}
zhao_data['referer'] = next_url
zhao_data['handlekey'] = 'a_poke_'+id
# print(zhao_data)
s.post(post_url, data=zhao_data,headers = my_headerc,timeout=0.3)
# 留言
post_url = 'http://www.yeayee.com/home.php?mod=space&uid='+id+'&do=wall'
s.get(post_url,headers = my_headerc)
post_url = 'http://www.yeayee.com/home.php?mod=spacecp&ac=comment&inajax=1'
zhao_data = {
'commentsubmit':'true',
'formhash':'34ddfce7',
'idtype':'uid'
}
zhao_data['referer'] = 'home.php?mod=space&uid=&do=wall'
zhao_data['handlekey'] = 'commentwall_'+id
zhao_data['id'] = int(id)
zhao_data['message'] = 'good day'
print(zhao_data)
s.post(post_url, data=zhao_data,headers = my_headerc,timeout=0.3)
else:
print('NO')
except:
pass







上一篇:没有了    下一篇:没有了

Copyright ©2018    易一网络科技|www.yeayee.com All Right Reserved.

技术支持:自助建站 | 领地网站建设 |短信接口 版权所有 © 2005-2018 lingw.net.粤ICP备16125321号 -5