获得指定网址指定标签内的内容或代码
uses msxml;
//从网页源文件中获得指定标签间的代码
function TForm1.GetStr(StrSource, StrBegin, StrEnd: string): string;
var
in_star, in_end: integer;
begin
in_star := AnsiPos(strbegin, strsource) + length(strbegin);
in_end := AnsiPos(strend, strsource);
Result := copy(strsource, in_star, in_end - in_star);
end;
//信息列表点击
procedure TForm1.btn1Click(Sender: TObject);
const
url = 'http://www.xxx.com';
var
req: IXMLHTTPRequest;
StrStream: TStringStream;
SetNoteStr: string;
begin
//利用 IXMLHTTPRequest 获取网页源代码,在调用函数GetStr截取需要的代码
req := CoXMLHTTPRequest.Create;
req.open('Get', url, False, EmptyParam, EmptyParam);
req.send(EmptyParam);//获取标签直接的代码
SetNoteStr := GetStr(req.responseText, '</script></center>', 'document.body.oncopy=function');StrStream := TStringStream.Create(SetNoteStr);
try
StrStream.Position := 0;//直接写入WebBrowser
(WebBrowser.Document as IPersistStreamInit).Load(TStreamadapter.Create(StrStream));
finally
StrStream.Free;end;
end;