在一个网页上有两个submit 按钮。一个是搜索的。一个是发帖的如果直接 o :=WebBrowser1.oleobject.document.all.item('submit',0);
o.Click;
的话它会执行搜索操作。现在我想实现发帖。该怎么修改代码呢。 两个提交的源代码如下
<input class="s-btn" type="submit" name="submit" value=" " />//搜索 <input class="btn fl b" style="padding:0 1em;*padding:0;width:70px;height:25px;" type="submit" name="Submit" value=" 提 交 " />//发帖谢谢了
o.Click;
的话它会执行搜索操作。现在我想实现发帖。该怎么修改代码呢。 两个提交的源代码如下
<input class="s-btn" type="submit" name="submit" value=" " />//搜索 <input class="btn fl b" style="padding:0 1em;*padding:0;width:70px;height:25px;" type="submit" name="Submit" value=" 提 交 " />//发帖谢谢了
<input class="s-btn" type="submit" name="submit" value=" " />//搜索
当subimt取值为空时候,搜索
当Submit value=" 提 交"时候,为 发帖.那么你可以在
o :=WebBrowser1.oleobject.document.all.item('submit',0);
前,先把
Submit=" 提 交"试验一下.
const pDisp: IDispatch; var URL: OleVariant);
var
//HTMLDocument1:IHTMLDocument;
ElementCollection:IHTMLElementCollection;
HTMLSelectElement:IHTMLSelectElement;
HTMLInputElement:IHTMLInputElement;
HTMLInputTextElement:IHTMLInputTextElement;
Dispatch: IDispatch;
k:integer;
begin
memo1.Lines.Add(WebBrowser1.LocationURL);
//if WebBrowser1.LocationURL <>'http://reg.qq.com' then exit;
/// HTMLDocument1 := IHTMLDocument2(WebBrowser1.Document);
ElementCollection := IHTMLDocument2(WebBrowser1.Document).all;
if ElementCollection=nil then exit;
for k := 0 to ElementCollection.length - 1 do begin
Dispatch := ElementCollection.item(k, 0);
if Succeeded(Dispatch.QueryInterface(IHTMLInputElement,HTMLInputElement)) then
begin
if (HTMLInputElement.type_='submit')and(HTMLInputElement.name='submit') then
begin
HTMLInputElement.value := ' 提 交'; end;
end
end;
end;
代码如下: procedure SubmitForm;
var
doc: IHTMLDocument2;
ElementCollection: IHTMLElementCollection;
HTMLFormElement: IHTMLFormElement;
i: integer;
sFormName: string;
begin
sFormName := 'FORM';//表单名, 取网页里具体要提交的表单的名称
doc := (WebBrowser.Document as IHTMLDocument2);
ElementCollection := doc.Get_forms; for i := 0 to ElementCollection.length - 1 do
begin
HTMLFormElement := ElementCollection.item(i, varempty) as IHTMLFormElement;
if SameText(sFormName, HTMLFormElement.name) then
begin
HTMLFormElement.submit;
break;
end;
end;
end;