我想写一个程序将网页代码中想要的字符串过滤出来.但是不知道从那里下手,那位有这方面的经验或例程让我借鉴下,还有,我应该从那里着手做??谢谢..

解决方案 »

  1.   

    去google 查一查关于BHO 和IEHelper 的资料,他们是用来做IE 插件的,可以在IE 做动作的时候拦截下下载的网页代码,供你修改。当然,你要有一点COM 的基础。祝好运。
      

  2.   

    如果有特定的条件过滤语句,pageproducer就很不错(不知道是不是这样拼写)就用过一次
    如果想读取table等里的内容,放到stringgrid等里,就必须熟练pos,copy函数.
    还有就是mshtml的IHTMLElementCollection,它可以轻松读取代码中的元素集,然后运用到code中
    下面提供一个html解析器的代码,把代码转换成定义(不知道如何解释,用一用就知道了)
    procedure HTMLParser(Source,Target:TStrings);
    var i,j:integer;
       s:String;
       ws:wideString;
       InCmd,InStr,CmdOK:boolean;
       CmdType,StrType:String;
       CmdData,StrData:String;
       Data:String;
    begin
      Target.Clear;
      InCmd:=false;
      InStr:=False;
      CmdOk:=false;
      CmdType:='';
      StrType:='';
      CmdData:='';
      StrData:='';
      data:='';
      for i:=0 to source.count-1 do
      begin
        ws:=source[i];
        for j:=1 to length(ws) do
        begin
          s:=ws[j];
          if s<' ' then continue;
          
          if InCmd then
          begin
            if InStr then
            begin
              if s=StrType then
              begin
                CmdData:=CmdData+StrType+StrData+StrType;
                InStr:=False;
                StrType:='';
                StrData:='';
              end
              else
              begin
                StrData:=StrData+s;
              end;
            end
            else if (s='"') or (s='''') then
            begin
               InStr:=True;
               StrData:='';
               StrType:=s;
            end
            else if s='>' then
            begin
               Target.add('<'+CmdType+' '+CmdData+'>');
               InCmd:=false;
               CmdType:='';
               CmdData:='';
               CmdOk:=false;
            end
            else if not CmdOK then
            begin
               if s=' ' then
               begin
                 CmdOK:=True;
                 CmdData:='';
               end
               else
               begin
                  CmdType:=CmdType+s;
               end;
            end
            else
            begin
               CmdData:=CmdData+s;
            end;
          end
          else
          begin
            if s='<' then
            begin
               if data<>'' then target.add(data);
               data:='';
               InCmd:=true;
               CmdType:='';
               CmdData:='';
               CmdOk:=false;
            end
            else
            begin
              data:=data+s;
            end;
          end;
        end;
      end;
      if data<>'' then target.add(data);
    end;
      

  3.   

    if those tools/libraries are too heavy for you, you can always use regular expressions to extract useful informationRegular Expressions for Delphi
    http://www.zeitungsjunge.de/delphi/pcre/index.htm
      

  4.   

    that is a little complicated, since these web sites don't provide standard programmatic interface like a web service, the best you can do is to extract the post form format (<form ..><input type=...>...</form>) from these sites, and set these fields programmatically, then do a HTTP POST. But it may not be worth your time to do that, you may as well do it manually