51Testing软件测试论坛
标题:
我写的论坛随机访问回帖脚本
[打印本页]
作者:
wfbobby
时间:
2008-6-9 21:28
标题:
我写的论坛随机访问回帖脚本
学了6天lr出来练练手,本来准备拿51论坛开刀。怕老师KO我。首先注册个论坛
http://wfbobby.5d6d.com
。进入新论坛后没帖子怎么办。先写个脚本随机发新帖循环N次。。。结果机器比较差只成功的发了48帖。有了论坛怎么来随机访问不同的页面再在不同页面上随机的去回复论坛的帖子呢?以下是我写的脚本
===================================
#include "web_api.h"
Action()
{
int snum,snum1,snum2,pg;
char link[100],link1[100],link2[100],link3[100],link4[100],link5[100],link6[100],sno[100],sno1[100],sno2[100];
srand(time(NULL));
web_add_cookie("CM2_sid=wub9lZ; DOMAIN=wfbobby.5d6d.com");
web_add_cookie("ins_nv=2; DOMAIN=wfbobby.5d6d.com");
web_add_cookie("ins_vt=9; DOMAIN=wfbobby.5d6d.com");
web_add_cookie("CM2_cookietime=315360000; DOMAIN=wfbobby.5d6d.com");
web_add_cookie("CM2_auth=UBghZWikzHbgry5bVYxC36BBQMk25XBz6wgpu0Z%2BmvKOu1etw6ZI1%2BYdzeoNscx3uOUbfwd86cX1n82vdAlz8X; DOMAIN=wfbobby.5d6d.com");
web_add_cookie("CM2_uc_uid=0; DOMAIN=wfbobby.5d6d.com");
web_add_cookie("CM2_visitedfid=2; DOMAIN=wfbobby.5d6d.com");
web_add_cookie("CM2_smile=1D1D0D2; DOMAIN=wfbobby.5d6d.com");
web_add_cookie("CM2_onlineusernum=1; DOMAIN=wfbobby.5d6d.com");
web_url("wfbobby.5d6d.com",
"URL=http://wfbobby.5d6d.com/",
"TargetFrame=",
"Resource=0",
"RecContentType=text/html",
"Referer=",
"Snapshot=t1.inf",
"Mode=HTML",
EXTRARES,
"Url=http://images.5d6d.net/orig/google.png", "Referer=", ENDITEM,
"Url=http://images.5d6d.net/dz61/Beijing2008/menu_bg.gif", ENDITEM,
"Url=http://images.5d6d.net/dz61/Beijing2008/arrow_down.gif", ENDITEM,
"Url=http://images.5d6d.net/dz61/Beijing2008/forumbox_head.gif", ENDITEM,
"Url=http://images.5d6d.net/dz61/Beijing2008/menu_itemline.gif", ENDITEM,
"Url=http://images.5d6d.net/dz61/Beijing2008/forumlink.gif", ENDITEM,
"Url=http://images.5d6d.net/dz61/Beijing2008/cat_bg.gif", ENDITEM,
"Url=http://images.5d6d.net/dz61/Beijing2008/forum2.gif", ENDITEM,
"Url=http://images.5d6d.net/dz61/Beijing2008/altbg1.gif", ENDITEM,
"Url=http://images.5d6d.net/dz61/Beijing2008/online.gif", ENDITEM,
"Url=http://images.5d6d.net/dz61/Beijing2008/portalbox_bg.gif", ENDITEM,
"Url=http://images.5d6d.net/dz61/Beijing2008/usericon.gif", ENDITEM,
LAST);
web_reg_save_param("fenye",
"LB=<div class=\"pages\"><em> ",
"RB= ",
"Ord=all",
"Search=All",
LAST);
web_url("默认版块",
"URL=http://wfbobby.5d6d.com/forum-2-1.html",
"TargetFrame=",
"Resource=0",
"RecContentType=text/html",
"Referer=http://wfbobby.5d6d.com/",
"Snapshot=t2.inf",
"Mode=HTML",
EXTRARES,
"Url=http://images.5d6d.net/dz61/Beijing2008/folder_s.gif", ENDITEM,
"Url=http://images.5d6d.net/dz61/Beijing2008/pollsmall.gif", ENDITEM,
"Url=http://images.5d6d.net/dz61/Beijing2008/activitysmall.gif", ENDITEM,
"Url=http://images.5d6d.net/dz61/Beijing2008/rewardsmall.gif", ENDITEM,
"Url=http://images.5d6d.net/dz61/Beijing2008/debatesmall.gif", ENDITEM,
"Url=http://images.5d6d.net/dz61/Beijing2008/multipage.gif", ENDITEM,
LAST);
lr_think_time( 333 );
//随机取帖子拥有的页数,原理是总帖子/每页显示20帖=页码数
pg=atoi(lr_eval_string("{fenye_1}"));
if (pg%20==0)
pg=pg/20;
else
pg=(pg/20)+1;
//snum2=rand()%atoi(lr_eval_string("{fenye_1}"))+1;
lr_output_message("%d",pg);
pg=rand()%pg+1;
lr_output_message("%d",pg);
itoa(pg,sno2,10);
strcpy(link5,"URL=http://wfbobby.5d6d.com/forum-2-");
strcat(link5,sno2);
strcat(link5,".html");
//拦截这个是论坛帖子名字.
web_reg_save_param("tiename",
"LB/DIG=-1-#.html\">",
"RB=</a></span>",
"Ord=all",
"Search=All",
LAST);
//拦截帖子真实连接ID
web_reg_save_param("tienum",
"LB=span id=\"thread_",
"RB=\"><a",
"Ord=all",
"Search=All",
LAST);
//偷懒了这个名字也要拦截下自动变的。省略下
web_url("2",
//"URL=http://wfbobby.5d6d.com/forum-2-2.html",
link5,
/*"TargetFrame=",
"Resource=0",
"RecContentType=text/html",
"Referer=http://wfbobby.5d6d.com/forum-2-1.html",
"Snapshot=t3.inf",
"Mode=HTML",*/
LAST);
//产生随机点当前板块的帖子的随机数
snum=rand()%atoi(lr_eval_string("{tiename_count}"))+1;
snum1=rand()%atoi(lr_eval_string("{tienum_count}"))+1;
lr_output_message("%d",snum);
strcpy(link,"{link_");
strcpy(link1,"URL=http://wfbobby.5d6d.com/thread-{tienum_");
strcpy(link2,"Action=http://wfbobby.5d6d.com/post.php?action=reply&fid=2&tid={tienum_");
strcpy(link3,"Referer=http://wfbobby.5d6d.com/post.php?action=reply&fid=2&tid={tienum_");
strcpy(link6,"URL=http://wfbobby.5d6d.com/post.php?action=reply&fid=2&tid={tienum_");
strcpy(link4,"Referer=http://wfbobby.5d6d.com/viewthread.php?tid={tienum_");
itoa(snum,sno,10);
itoa(snum1,sno1,10);
strcat(link,sno);
strcat(link1,sno1);
strcat(link2,sno1);
strcat(link3,sno1);
strcat(link6,sno1);
strcat(link4,sno1);
strcat(link,"}");
strcat(link1,"}-1-1.html");
strcat(link2,"}&extra=&replysubmit=yes");
strcat(link3,"}&extra=");
strcat(link6,"}&extra=");
strcat(link4,"}&pid=54&page=1&extra=");
lr_output_message(lr_eval_string(link));
//随机取帖子
web_url(lr_eval_string("{link}"),
link1,
//web_url("66666666",
//"URL=http://wfbobby.5d6d.com/thread-29-1-2.html",
//link1,
/*"TargetFrame=_blank",
"Resource=0",
"RecContentType=text/html",
"Referer=http://wfbobby.5d6d.com/forum-2-2.html",
"Snapshot=t4.inf",
"Mode=HTML",
EXTRARES,
"Url=http://images.5d6d.net/dz61/Beijing2008/user_online.gif", ENDITEM,
"Url=http://images.5d6d.net/dz61/Beijing2008/user_add.gif", ENDITEM,
"Url=http://images.5d6d.net/dz61/Beijing2008/buddy_sendpm.gif", ENDITEM,
"Url=http://images.5d6d.net/dz61/Beijing2008/headactions_line.gif", ENDITEM,*/
LAST);
//这行是模拟用户回帖填写页面
web_url("reply.gif",
//"URL=http://wfbobby.5d6d.com/post.php?action=reply&fid=2&tid=29&extra=",
link6,
/*"TargetFrame=",
"Resource=0",
"RecContentType=text/html",
"Referer=http://wfbobby.5d6d.com/thread-29-1-2.html",
"Snapshot=t5.inf",
"Mode=HTML",
EXTRARES,
"Url=/images/common/editor.gif", "Referer=http://wfbobby.5d6d.com/post.php?action=reply&fid=2&tid=29&extra=", ENDITEM,*/
LAST);
/*web_submit_data("post.php",
"Action=http://wfbobby.5d6d.com/post.php?action=reply&fid=2&tid=29&extra=&replysubmit=yes",
"Method=POST",
"EncType=multipart/form-data",
"TargetFrame=",
"RecContentType=text/html",
"Referer=http://wfbobby.5d6d.com/post.php?action=reply&fid=2&tid=29&extra=",
"Snapshot=t6.inf",
"Mode=HTML",
ITEMDATA,
"Name=formhash", "Value=0b98e6f0", ENDITEM,
"Name=subject", "Value=", ENDITEM,
"Name=posteditor_mediatyperadio", "Value=on", ENDITEM,
"Name=message", "Value=success!", ENDITEM,
"Name=previewbutton", "Value=预览帖子", ENDITEM,
"Name=attach[]", "Value=", "File=yes", ENDITEM,
"Name=localid[]", "Value=", ENDITEM,
"Name=attachperm[]", "Value=0", ENDITEM,
"Name=attachprice[]", "Value=0", ENDITEM,
"Name=attachdesc[]", "Value=", ENDITEM,
"Name=attach[]", "Value=", "File=yes", ENDITEM,
"Name=localid[]", "Value=1", ENDITEM,
"Name=attachperm[]", "Value=0", ENDITEM,
"Name=attachprice[]", "Value=0", ENDITEM,
"Name=attachdesc[]", "Value=", ENDITEM,
"Name=wysiwyg", "Value=0", ENDITEM,
"Name=fid", "Value=2", ENDITEM,
LAST);*/
//回帖、
web_submit_data("post.php",
//"Action=http://wfbobby.5d6d.com/post.php?action=reply&fid=2&tid=1&extra=&replysubmit=yes",
link2,
"Method=POST",
"EncType=multipart/form-data",
"TargetFrame=",
"RecContentType=text/html",
link3,
"Snapshot=t8.inf",
"Mode=HTML",
ITEMDATA,
"Name=formhash", "Value=0b98e6f0", ENDITEM,
"Name=subject", "Value=", ENDITEM,
"Name=posteditor_mediatyperadio", "Value=on", ENDITEM,
"Name=message", "Value={word}", ENDITEM,
"Name=previewbutton", "Value=预览帖子", ENDITEM,
"Name=attach[]", "Value=", "File=yes", ENDITEM,
"Name=localid[]", "Value=", ENDITEM,
"Name=attachperm[]", "Value=0", ENDITEM,
"Name=attachprice[]", "Value=0", ENDITEM,
"Name=attachdesc[]", "Value=", ENDITEM,
"Name=attach[]", "Value=", "File=yes", ENDITEM,
"Name=localid[]", "Value=1", ENDITEM,
"Name=attachperm[]", "Value=0", ENDITEM,
"Name=attachprice[]", "Value=0", ENDITEM,
"Name=attachdesc[]", "Value=", ENDITEM,
"Name=wysiwyg", "Value=0", ENDITEM,
"Name=fid", "Value=2", ENDITEM,
EXTRARES,
"Url=/pm.php?checknewpm=0.5004579638903337&inajax=1&ajaxtarget=pmnotice", "Referer=http://wfbobby.5d6d.com/viewthread.php?tid=1&pid=54&page=1&extra=", ENDITEM,
LAST);
return 0;
}
作者:
wfbobby
时间:
2008-6-9 21:29
成功后的结果。去了随机5次中的一次的截图
作者:
wfbobby
时间:
2008-6-9 21:30
完整的代码包
作者:
wfbobby
时间:
2008-6-9 21:32
我还是想轰51的论坛。谁借我个胆子
作者:
zhaoxing12
时间:
2008-6-10 11:07
小哥,你真牛!
作者:
云层
时间:
2008-6-10 13:35
回复的内容太简单了,你要搞到发贴回贴能在内容配对的上,那么直接让你3阶段考试通过好了。。。
作者:
Zee
时间:
2008-6-10 13:55
自己搭个环境最好。
作者:
wfbobby
时间:
2008-6-10 22:47
原帖由
云层
于 2008-6-10 13:35 发表
回复的内容太简单了,你要搞到发贴回贴能在内容配对的上,那么直接让你3阶段考试通过好了。。。
鄙视你老师。。。。不让我过。。。内容配对。。。我研究下先
作者:
wfbobby
时间:
2008-6-10 22:52
其实说实话。本来以为掌握了,真正独立动手做时候才发现。理解得不深刻。关联做好了。以为返回值在下面就能取道。结果Lr_eval_string做了半天取不出来参数返回值。真正心里抓狂啊。到处通缉云层老师未果。老天开眼让我摸索出来了啊55555555。原来放的位置也如此重要。再次鄙视云层老师
作者:
shen1936
时间:
2008-6-11 10:00
不仅仅是鄙视!
作者:
云层
时间:
2008-6-11 11:07
如果你用lr_save_sting会发现还能简单很多
作者:
dishiwujian
时间:
2008-6-11 18:21
智能回帖
貌似算是人工智能的范畴……
另外:似乎应该是LR_SAVE_STRING,云版主拼写错了
作者:
wfbobby
时间:
2008-6-11 21:04
看到下面2个图发觉这个随机回帖脚本有BUG
作者:
wfbobby
时间:
2008-6-11 21:09
//拦截这个是论坛帖子名字.
web_reg_save_param("tiename",
"LB/DIG=-1-##.html\">",
"RB=</a></span>",
"Ord=all",
"Search=All",
LAST);
如果要拦截十位以上必定会要做或者
//拦截这个是论坛帖子名字.
web_reg_save_param("tiename",
"LB/DIG=-1-###.html\">",
"RB=</a></span>",
"Ord=all",
"Search=All",
LAST);
如此之类等等
作者:
wfbobby
时间:
2008-6-11 21:21
itoa(pg,sno2,10);
strcat(bobby,sno2);
//拦截这个是论坛帖子名字.
web_reg_save_param("tiename",
"LB/DIG=-1-bobby.html\">",
"RB=</a></span>",
"Ord=all",
"Search=All",
LAST);
貌似用这段代码替换掉上面拦截论坛帖子名字这段可以解决,想法是bobby这个位置是代表所属的页码,pg是用来产生页码的。用产生的页面同时替换拦截这里的变量。
作者:
hehe911
时间:
2008-6-17 20:47
作者:
931743010
时间:
2011-7-4 18:48
唯一的 带3阶段考试的 帖子,,,
作者:
v_v
时间:
2012-8-30 00:04
感觉楼主些复杂了,一路拼接好多啊。。
欢迎光临 51Testing软件测试论坛 (http://bbs.51testing.com/)
Powered by Discuz! X3.2