如何搜尋某一網頁上的<TD>標籤後面的內容? |
答題得分者是:chris_shieh
|
Andy Wu
一般會員 發表:17 回覆:25 積分:18 註冊:2004-02-25 發送簡訊給我 |
< tr>
< td class="sbody" width="20%" bgcolor="#F3F3F3" nowrap>< font color="#006699">人數< /font>< /td>
< td class="maf" width="30%" bgcolor="#F3F8F8>< font color=red>12345< /font>< /td>
< /tr> 假設某一網頁有一段原始內容如上,請問是否可以在該網頁上搜尋「人數」,傳回「12345」這個數值? 目前使用D6 TWebBrowser
|
chris_shieh
高階會員 發表:46 回覆:308 積分:240 註冊:2004-04-26 發送簡訊給我 |
procedure TForm1.Button1Click(Sender: TObject); var bFound:Boolean; sSrcFile, TagKey, strTmp:String; iPos, iPos2:integer; i:integer; begin sSrcFile:='C:\test.html'; Memo1.Lines.LoadFromFile(sSrcFile); bFound:=False; TagKey:=Edit1.Text;//'[red]', the tag just before target for i := 0 to Memo1.Lines.Count-1 do begin if not bFound then begin iPos:=Pos('人數',Memo1.Lines[i]); bFound:=iPos>0; end; if bFound then begin iPos:=Pos(TagKey, Memo1.Lines[i]); if iPos>0 then begin iPos2:=PosEx('', Memo1.Lines[i], iPos); if iPos2>0 then begin Label1.Caption:=Copy(Memo1.Lines[i],iPos + Length(TagKey), iPos2-iPos-Length(TagKey)); break; end; end; end; end; end;@瞭解越多.懂得越少@ 發表人 - chris_shieh 於 2005/09/08 18:19:49 |
paa
初階會員 發表:50 回覆:101 積分:30 註冊:2005-02-01 發送簡訊給我 |
var
sfind1,sfind2,str,s:string;
begin
s:=richedit1.Lines.Text;
sFind1:='<';//輸入字串
sfind2:='>';
while Pos(sFind1, s) > 0 do //一行裡有找到往下跑
begin
str:=copy(s,Pos(sFind1, s),Pos(sFind2, s)-Pos(sFind1, s) 1);
s:=StringReplace(s,str,'',[rfReplaceAll]);
showmessage(s);
end;
end;
|
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |