列如有一网页
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
</head>
<form name="form1" method="post" action="">
  <input name="T1" type="text" id="t1" value="dfsdfsdf">
</form>
</body>
</html>
能否取出T1的值传到Tedit中?

解决方案 »

  1.   

    肯定是可以取出来的,最笨的办法是按字符串'<input ',去查找匹配,取其后的value值.不过我考虑可以把html的内容部分装入到一个xmlDocument中,让它去解析,这样可以更容易的找到所要的信息. 但是并不是所有的html的内容都能被xmlDocument识别的,对于不能识别的或解析失败的,再按字符串去查找.如果你的网页的结构是固定的,那应该是非常简单就可以实现的.我上面讨论的是对于完全未知的网页,如果是结构固定的网页,完全可以用XMLDocument去帮忙了.
      

  2.   


    function FillForm(WebBrowser: TWebBrowser; FieldName: string; Value: string): Boolean; 
    var 
      i, j: Integer; 
      FormItem: Variant; 
    begin 
      Result := False; 
      //no form on document 
      if WebBrowser.OleObject.Document.all.tags('FORM').Length = 0 then 
      begin 
        Exit; 
      end; 
      //count forms on document 
      for I := 0 to WebBrowser.OleObject.Document.forms.Length - 1 do 
      begin 
        FormItem := WebBrowser.OleObject.Document.forms.Item(I); 
        for j := 0 to FormItem.Length - 1 do 
        begin 
          try 
            //when the fieldname is found, try to fill out 
            if FormItem.Item(j).Name = FieldName then 
            begin 
              FormItem.Item(j).Value := Value; //修改这里, 读FormItem.Item(j).Value 
              Result := True; 
            end; 
          except 
            Exit; 
          end; 
        end; 
      end; 
    end; 
    //When the document is complete try to fill out the field homepage with the url 
    procedure TForm1.WebBrowser1DocumentComplete(Sender: TObject; 
      const pDisp: IDispatch; var URL: OleVariant); 
    begin 
      if FillForm(WebBrowser1, 'homepage', 'http://www.swissdelphicenter.ch') = False then 
        ShowMessage('Error. Field not available or no Form found.');
    end;// Show the Webbrowser-Progress in Label1 
    procedure TForm1.WebBrowser1ProgressChange(Sender: TObject; Progress, ProgressMax: Integer); 
    begin 
      if ProgressMax = 0 then 
      begin 
        label1.Caption := ''; 
        Exit; 
      end; 
      try 
        if (Progress <> -1) and (Progress <= ProgressMax) then 
          label1.Caption := IntToStr((Progress * 100) div ProgressMax) + '% loaded...' 
        else 
          label1.Caption := ''; 
      except 
        on EDivByZero do Exit; 
      end; 
    end; 
    //For example you can load the page /en/addtip.php to the TWebBrowser 
    //When the document is Complete the form where you can put your homepage 
    //address is filled out 
    procedure TForm1.Button1Click(Sender: TObject); 
    begin 
      Webbrowser1.Navigate('http://www.swissdelphicenter.ch/en/addtip.php'); 
      // Show the Titel of the currently active Webpage in the titlebar 
      // Den Titel der aktuellen Webseite in der Titeleiste anzeigen 
      Caption := Webbrowser1.OleObject.Document.Title; 
    end;