图1是WRSP的使用的图形界面,根据自己的需要填写相关的内容,就会生成相关的脚本。
我来看看界面中相关的内容有Parameter Name、Left Boundary、Right Boundary、Instance、Relative Frame ID、Not Found、Search in、Sava length、Save offset等等的设置。我们以下通过例子来说他们的作用
现在我们打开百度网站看到里面然后查看该页的源码。
以下就是百度网页源码的一部分代码
<br><br><br><br><table cellpadding=0 cellspacing=0 id=l><tr><td><div id=m><a ōnclick=s(this)href=http://news.baidu.com>新 闻</a><b>网 页</b><a ōnclick=s(this) href=http://tieba.baidu.com>贴 吧</a><a ōnclick=s(this) href=http://zhidao.baidu.com>知 道</a><a ōnclick=s(this) href=http://mp3.baidu.com>MP3</a><a ōnclick=s(this) href=http://image.baidu.com>图 片</a><a ōnclick=s(this) href=http://video.baidu.com>视 频</a></div></td></tr></table> |
现在我们想在百度页面中《新闻》两个字出来,下一步进行搜索做为关键词去使用。
代码中的红色的字体的
Action() { web_reg_save_param("keyword", //keyword就是的PARAMETER NAME "LB=href=http://news.baidu.com>", // Left Boundary "RB=</a>", // Right Boundary LAST); //以上定义的关联会在在以下打开的www.baidu.com中获要的数据 //从这个地方我们可以看出想要在对应的页面上获得对应的数据就得在打开页面该页面函数前面定义好关联函数。 web_url("www.baidu.com", "URL=http://www.baidu.com/", "Resource=0", "RecContentType=text/html", "Snapshot=t1.inf", "Mode=HTML", LAST); //通过以上的关联我们在www.baidu.com的页面中取得的值是:新 闻 //在以下的脚本我们就是使用关联出来的参数进行搜索 web_submit_data("s", "Action=http://www.baidu.com/s", "Method=GET", "EncType=", "RecContentType=text/html", "Referer=http://www.baidu.com/", "Snapshot=t5.inf", "Mode=HTTP", ITEMDATA, "Name=wd", "Value={keyword}", ENDITEM, //这就是使用keyword使用的时候记得使用大括号括住参数名 LAST); return 0; } |
以上的脚本是用《新 闻》来做关键字的不适合我们的需求,下面我们优化一下关联把我们要的《新闻》取出来。
Action() { web_reg_save_param("keyword1", //keyword1就是的PARAMETER NAME "LB=href=http://news.baidu.com>", // Left Boundary "RB=</a>", // Right Boundary "SaveLen=2", //保存字段的长度 "SaveOffset=0" , //从那位字段开始保存 LAST); //这个关联去出《新》字 web_reg_save_param("keyword2", //keyword2就是的PARAMETER NAME "LB=href=http://news.baidu.com>", // Left Boundary "RB=</a>", // Right Boundary "SaveLen=2",//保存字段的长度 "SaveOffset=8",//从那位字段开始保存 LAST);这个关联去出《闻》字 web_url("www.baidu.com", "URL=http://www.baidu.com/", "Resource=0", "RecContentType=text/html", "Snapshot=t1.inf", "Mode=HTML", LAST); web_submit_data("s", "Action=http://www.baidu.com/s", "Method=GET", "EncType=", "RecContentType=text/html", "Referer=http://www.baidu.com/", "Snapshot=t5.inf", "Mode=HTTP", ITEMDATA, "Name=wd", "Value={ keyword1}{ keyword2}", ENDITEM, //使用的时候这样使用就可以了 LAST); return 0; } |
累了-案例一就到这结束