控制所有WebBrowser元件包括已經開啟的網頁內的圖片

来源:互联网 发布:mac 散热 键盘 编辑:程序博客网 时间:2024/06/10 17:39
當然可以呀:

//使用一個AP的Button登入WebBrowser的帳號================
procedure TForm1.Button1Click(Sender: TObject);
var
Docs, Edits : OleVariant;
begin
Docs :=WebBrowser1.Document;
(*此處只適用於http://tw.login.yahoo.com/cgi-bin/login.cgi?srv=www&from=http://tw.yahoo.com/該網頁的輸入*)
Edits :=Docs.GetElementByID('login');
Edits.Value :='你的KIMO帳號';
Edits :=Docs.GetElementByID('passwd');
Edits.Value :='你的KIMO密碼';
//登入
WebBrowser1.OleObject.Document.GetElementByID('submit').Click;
end;
//使用一個AP的Button登入WebBrowser的帳號================

//列出所有影像檔的位置======================
procedure TForm1.Label3Click(Sender: TObject);
var
  Document: IHtmlDocument2;
  str: string;
begin
Form1.ListBox2.Clear;
for i := 0 to WebBrowser1.OleObject.Document.Images.Length - 1 do
    begin
     Document := WebBrowser1.Document as IHtmlDocument2;
     Str := (Document.Images.Item(i, 0) as IHTMLImgElement).href;
     Form1.ListBox2.Items.Add(Str); //列出這個網站內所有的影像檔位置
     //改變網頁中的圖檔=========================
     if Pos('pscnet_login_10.gif', Str) <> 0 then
     begin
     (Document.Images.Item(i, 0) as IHTMLImgElement).Set_src(Form1.Edit2.Text); //Form1.Edit2.Text放要改變的圖檔路徑=======
     end;
     //改變網頁中的圖檔=========================
    end;
end;
//列出所有影像檔的位置====================== 
原创粉丝点击