WebBrowser 可否实现点击网页中图片的功能? 如果可以应该如何实现呢? 谢谢!

解决方案 »

  1.   

    下面举的例子,网页地址是www.sina.com.cn,图片是里面的一个图片,地址是http://image2.sina.com.cn/ent/pc/2006-03-20/55/U107P28T55D6474F918DT20060320121449.jpgUses MSHtml;procedure TForm1.Button1Click(Sender: TObject);
    var
      i:integer;
      HtmlDoc:IHTMLDocument2;
      TypeElement:variant;
    begin
      WebBrowser1.Navigate('http://www.sina.com.cn/');
      While WebBrowser1.ReadyState <> READYSTATE_COMPLETE do
            Application.ProcessMessages;
      HtmlDoc:=WebBrowser1.Document as IHTMLDocument2;
      for i:=0 to HtmlDoc.all.length-1 do
      begin
        TypeElement:=Htmldoc.all.item(i,varempty);
        if Uppercase(TypeElement.tagName)='INPUT' then
        begin
          //......;
        end
        else if Uppercase(TypeElement.tagName)='IMG' then  
        begin
          {memo1.Lines.Append(TypeElement.src);//所有图的名字}
          if TypeElement.src='http://image2.sina.com.cn/ent/pc/2006-03-20/55/U107P28T55D6474F918DT20060320121449.jpg'then  //提交的图
          begin
             TypeElement.Click;  //点击提交
             While WebBrowser1.ReadyState <> READYSTATE_COMPLETE do
                   Application.ProcessMessages;
          end;
        end;
      end;
    end;