delphi做这样的网页该用什么思路呢(30)

  • 主题发起人 主题发起人 angel725
  • 开始时间 开始时间
A

angel725

Unregistered / Unconfirmed
GUEST, unregistred user!
是个网页游戏,玩聊的时候玩玩,可是有些操作天天都是一样的,想自己写个自动工作的程序,可是那些网上的很多显示的东西都是通过变量取得的。比如 <DIV class=navmenu> <SPAN id=nMainMenu> <A class="" onmousedown="om.setIcon(this,1,'chara','undefined')" id=chara onmouseover="om.setIcon(this,2,'chara','undefined')" onclick="javascript:om.clickmain('chara',this,'undefined','undefined');om.mainhintname='chara';om.main_hint_open('chara','');om.clickchild('charabasic','人物',this);om.setIcon(this,3,'chara','undefined')" onmouseout="om.setIcon(this,0,'chara','undefined')" href="javascript:void(0)" ?> <IMG alt=人物 src="http://img8.gamebto.com/gamebto/images/default/chara.gif"> </A> <DIV style-?width:30px;?> </DIV> </SPAN> </DIV> 这是看人物信息的,想看的话,就用鼠标点一下,可是用delphi怎么做呢? 昨日收入: <B class=yellow id=user_yesterdayearning>7,360 </B>G币 这是显示的一个收入值, 这是不是要分析包才能知道7360那个位置的接收数的变量啊? 没做过这样的。请多多帮忙?
 
unit Unit1;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, OleCtrls, SHDocVw, ExtCtrls, StdCtrls, ComCtrls, SynEditHighlighter, SynHighlighterJScript, SynEdit, SynHighlighterHtml;type TForm1 = class(TForm) Panel1: TPanel; Button1: TButton; PageControl1: TPageControl; TabSheet1: TTabSheet; TabSheet2: TTabSheet; Panel2: TPanel; WebBrowser1: TWebBrowser; SynEdit1: TSynEdit; SynJScriptSyn1: TSynJScriptSyn; CheckBox1: TCheckBox; CheckBox2: TCheckBox; Button2: TButton; TabSheet3: TTabSheet; SynEdit2: TSynEdit; SynHTMLSyn1: TSynHTMLSyn; procedure FormCreate(Sender: TObject); procedure Button1Click(Sender: TObject); procedure FormDestroy(Sender: TObject); procedure Button2Click(Sender: TObject); procedure PageControl1Change(Sender: TObject); private { Private declarations } public jsfn: string; procedure execScript(Script: string); end;var Form1: TForm1;implementation{$R *.dfm}uses MSHTML, ActiveX;function GetHTMLCode(WB: TWebBrowser; ACode: TStrings): Boolean;var ps: IPersistStreamInit; s: string; ss: TStringStream; sa: IStream;begin ps := WB.document as IPersistStreamInit; s := ''; ss := TStringStream.Create(s); try sa := TStreamAdapter.Create(ss, soReference) as IStream; Result := Succeeded(ps.Save(sa, Bool(True))); if Result then ACode.Add(ss.Datastring); finally ss.Free; end;end;procedure TForm1.FormCreate(Sender: TObject);begin jsfn := ExtractFilePath(Application.ExeName) + 'Script.js'; if FileExists(jsfn) then begin SynEdit1.Lines.LoadFromFile(jsfn); end; WebBrowser1.Navigate('http://s17.sg.9wee.com/index.php?p=NoData');end;procedure TForm1.execScript(Script: string);begin WebBrowser1.OleObject.Document.parentWindow.execScript(Script, 'javascript');end;procedure TForm1.Button1Click(Sender: TObject);begin execScript(SynEdit1.Lines.Text);end;procedure TForm1.FormDestroy(Sender: TObject);begin SynEdit1.Lines.SaveToFile(jsfn);end;procedure TForm1.Button2Click(Sender: TObject);begin SynEdit1.Lines.SaveToFile(jsfn);end;procedure TForm1.PageControl1Change(Sender: TObject);begin if PageControl1.ActivePageIndex = 2 then begin SynEdit2.Lines.Text := WebBrowser1.OleObject.Document.body.outerHtml; //GetHTMLCode(WebBrowser1, SynEdit2.Lines); end;end;end./////////Script.jsfunction getCookie(name) { var s='';    var prefix = name + "="     var cookieStartIndex = document.cookie.indexOf(prefix)     if (cookieStartIndex == -1)         return ''     var cookieEndIndex = document.cookie.indexOf(";", cookieStartIndex + prefix.length)     if (cookieEndIndex == -1)         cookieEndIndex = document.cookie.length     s= unescape(document.cookie.substring(cookieStartIndex + prefix.length, cookieEndIndex)) ; if (s==null) s=''; return s; } function wg(){var username = document.getElementById('username');if (username!= undefined ) { // 登陆 document.getElementById('username').value='h....'; document.getElementById('password').value='d....'; document.getElementById('Input').click(); document.cookie='cmd=登陆'; return; }var cmd= getCookie('cmd');if (cmd=='') cmd='城池动态';alert(cmd);var div;var div2;var div3;var table;var row;var element; var idx;var list; var s;if ( cmd=='建造' ){ document.getElementById('city_build_resource_a').click(); //资源建筑 document.cookie='cmd=资源建筑'; return;}if ( cmd=='资源建筑' ){ document.cookie='cmd=资源建筑'; div = document.getElementById('city_build_resource'); div = div.childNodes[0]; list=new Array(); idx=0; for(var i=1;i<div.childNodes.length;i++){ div2= div.childNodes; for(var j=0;j<div2.childNodes.length;j++) { div3=div2.childNodes[j]; if (div3.childNodes.length==4) { s=div3.childNodes[3].innerHTML; if(s.indexOf('onclick')>=0) { idx=list.length; list[idx]=div3; } } } } var minLevel=999; var Level=0; var idx=-1; for(var i=1;i<list.length;i++){ div=list; Level=0+div.childNodes[1].innerText; if (Level <minLevel) { minLevel= Level; idx=i; if (minLevel=0 ) break; } } if (idx<0) return; div=list[idx].childNodes[3]; if (div.innerText!='建') return ; document.cookie='cmd=资源建筑_建'; div.childNodes[0].click(); return;}if ( cmd=='资源建筑_建' ){ alert('1'); return;}if ( cmd=='城池动态' ){ document.getElementById('city_a').click(); //城池 document.getElementById('city_manage_a').click(); //管理 document.getElementById('city_manage_0_a').click(); //城池动态 div=document.getElementById('city_manage_0'); for(var i=0;i<div.childNodes.length;i++){ if ( div.childNodes.tagName=='TABLE' ) { table= div.childNodes; break; } } alert(table.rows.length) ; for(var arow=1;arow<table.rows.length;arow++){ row=table.rows[arow]; if (row.cells[8].innerText != '2' ) // 建造中 { alert(row.cells[0].innerText); row.cells[11].childNodes[0].click(); //查看 document.getElementById('city_resource_building_a').click(); document.cookie='cmd=建造'; break; } } return;} }wg();
 
用cookie模拟登录,然后解析结果(可以用正则表达式)即可(签名:中国软件人 http://bbs.cnsoftware.cn )
 
多人接受答案了。
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
后退
顶部