<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft DHTML Editing Control">
<TITLE></TITLE>
</HEAD>
<BODY>
<P>今天天气好吗?</P>
<P><INPUT type=radio value="Radio Button">不错</P>
<P><INPUT type=radio value="Radio Button">不行</P>
<P>可以访问你吗?</P>
<P><INPUT>可以,不过不要太久</P>
<P> </P>
</BODY>
</HTML>
以上如何从HTML代码方便读取INPUT框的内容,譬如将“今天天气好吗?,不错,不行”等在网页中的信息读出来,听说IHTMLDocument2可以方便实现,但Delphi6在导入Microsoft HTML Object Library后编译出错,请问有没有办法解决?
<HEAD>
<META NAME="GENERATOR" Content="Microsoft DHTML Editing Control">
<TITLE></TITLE>
</HEAD>
<BODY>
<P>今天天气好吗?</P>
<P><INPUT type=radio value="Radio Button">不错</P>
<P><INPUT type=radio value="Radio Button">不行</P>
<P>可以访问你吗?</P>
<P><INPUT>可以,不过不要太久</P>
<P> </P>
</BODY>
</HTML>
以上如何从HTML代码方便读取INPUT框的内容,譬如将“今天天气好吗?,不错,不行”等在网页中的信息读出来,听说IHTMLDocument2可以方便实现,但Delphi6在导入Microsoft HTML Object Library后编译出错,请问有没有办法解决?
<P><INPUT type=radio value="Radio Button">不错</P>
<P><INPUT type=radio value="Radio Button">不行</P>这些放在表单<form>里面处理,否则无法提交信息的,对了还要加一个一个提交按钮
完整的一个例子:
<form action='你的处理程序' methods=post>
<P>今天天气好吗?</P>
<P><INPUT type=radio value="Radio Button">不错</P>
<P><INPUT type=radio value="Radio Button">不行</P>
<p><input type=submit vlaue="提交"></p>根据你的程序再改改吧
另外要导入 Microsoft HTML Object Library,这个时间不短,耐心等待
procedure TMainFrm.GetFramesLink(CheckDoc: IHTMLDocument2; First: boolean);
var i : integer;
Document : IHTMLDocument2;
Frames : IHTMLFramesCollection2;
Element : IHTMLElement;
ElementName : OLEVariant;
FrameWindow : IHTMLWindow2;
FrameDocument : IHTMLDocument2;
Dispatch : IDispatch;
FrameCount : Integer;
AnchorString : string ;
begin
if First then
begin
//Get the main document
Document:= FInternetExplorer.Document as IHTMLDocument2;
if not Assigned(Document) then
exit;
//After we retrieve the document, we get the number of frames
Frames:=Document.Get_Frames;
//Test if there has frames
if not assigned(Frames) then
exit;
for i:=0 to Document.all.length-1 do
begin
Element:=Document.all.item(i,0) as IHTMLElement;
if not assigned(Element) then
continue;
if Element.tagName = 'FRAME' then
begin
ElementName:=Element.getAttribute('Name',0);
inc(FrameCount);
FrameList.Items.add(ElementName);
try
Dispatch:=Frames.item(ElementName);
Dispatch.QueryInterface(IHTMLWindow2,FrameWindow);
if not assigned(FrameWindow) then
continue;
FrameDocument:=FrameWindow.document;
if assigned(FrameDocument) then
GetFramesLink(FrameDocument,false);
except
on EOLEException do
begin
FrameList.Items.Delete(FrameList.Count-1);
dec(FrameCount);
continue;
end;
end;
end //if=Frame
else
if Element.tagName = 'A' then
begin
AnchorString := Element.innerText;
if AnchorString = '' then
AnchorString := '(Empty Name)';
// We know that the element is an IHTMLAnchorElement since the tagName
// is 'A'.
AnchorString := AnchorString + ' - ' +
(Element as IHTMLAnchorElement).href;
lstbxLinks.Lines.Add(AnchorString);
end;
end; //For i Schleife
end
else
begin
if not assigned(CheckDoc) then
exit;
Frames:=CheckDoc.get_frames;
if not assigned(Frames) then
exit;
for i:=0 to CheckDoc.all.length-1 do
begin
Element:=CheckDoc.all.item(i,0) as IHTMLElement;
if not Assigned(Element) then
continue;
if Element.tagName = 'FRAME' then
begin
ElementName:=Element.getAttribute('Name',0);
inc(FrameCount);
FrameList.Items.Add(ElementName);
try
Dispatch:=Frames.item(ElementName);
Dispatch.QueryInterface(IHTMLWindow2,FrameWindow);
if not assigned(FrameWindow) then
continue;
FrameDocument:=FrameWindow.document;
if assigned(FrameDocument) then
GetFramesLink(FrameDocument,false);
except
on EOLEException do
begin
FrameList.Items.Delete(FrameList.Count-1);
dec(FrameCount);
continue;
end;
end;
end //if=FRAME
else
if Element.tagName = 'A' then
begin
AnchorString := Element.innerText;
if AnchorString = '' then
AnchorString := '(Empty Name)';
// We know that the element is an IHTMLAnchorElement since the tagName
// is 'A'.
AnchorString := AnchorString + ' - ' +
(Element as IHTMLAnchorElement).href;
lstbxLinks.Lines.Add(AnchorString);
end;
end; //For i Loop
end;
end;
可以转换成自己需要的元素
我导入 Microsoft HTML Object Library后编译MSHTML_TLB出错,你是否会出现这样的问题?
2.用WebBrowser控件顯示Html文件
3.IHtmlDocument2(WebBrowser1.Document).Body.OuterText就是網頁的文本: