//目的:采购资源// 参数:wb1:内嵌Web浏览器// URLList:资源地址// GoodStype:资源类型 0:木头 1:石头 2:水晶 3:粮食// price:价格(默认0金16银)procedure BuyStock(wb1:TWebBrowser;URLList:TStrings;Goodstype:string='0';price:string='16');var irow:Integer; ITable:IHTMLTable; Row:IHTMLTableRow; Cell:IHTMLELement; chils:IHTMLElementCollection; i:integer;begin try wb1.Navigate(RefURL('http://sd1.duniu.com/market?by=price&asc=1&type=1&goodstype='+goodstype)); //等待页面加载完成 while wb1.ReadyState<>READYSTATE_COMPLETE do begin Application.ProcessMessages; end; //找到出售资源的表格,ct1为表格的ID if getElementById(wb1,'ct1')=nil then exit; if getElementByID(wb1,'ct1').tagName<>'TABLE' then Exit; ITable:= getElementByID(wb1,'ct1') as IHTMLTABLE; for irow:=1 to ITable.rows.length - 1 do begin row:=ITable.rows.item(irow,varEmpty) as IHTMLTableRow; //获得单价 cell:=Row.cells.item(3,varEmpty) as IHTMLELement; if StrToInt(MidStr(Cell.innerText,3,2))<= StrToInt(price) then begin //得到"操作”单元格的内容 cell:=Row.cells.item(5,varEmpty) as IHTMLELement; //得到"操作"的下级HTML元素,以找出连接 chils:=Cell.children as IHTMLElementCollection; for i:=0 to chils.length-1 do begin if ((chils.item(i,varEmpty)) as IHTMLElement).tagName='A' then begin //添加到URLList中,以备下面使用 URLList.Add(((chils.item(i,varEmpty)) as IHTMLElement).getAttribute('href',0)); break; end; end; end else Break; end; //如果找到可以采购的资源,就开始采购 while URLList.Count<>0 do begin wb1.Navigate(URLList[0]); while wb1.ReadyState<>READYSTATE_COMPLETE do begin Application.ProcessMessages; end; URLList.Delete(0); end; except end;end;这是我写的七龙纪的采购资源中的一段