本人用dephi想开发一个小工具读取实时的股票价格,该数据是由sina提供的如下:http://hq.sinajs.cn/list=sh601006在页面中显示没有问题
<head>
<title></title>
</head>
<body></body>
<script type="text/javascript" src="http://hq.sinajs.cn/list=sz000735" charset="gb2312"></script>
<script type="text/javascript">
var elements = hq_str_sz000735.split(",");
document.write("current price:" + elements[3]);
</script>
</html>请问如果用dephi如何得到该数据,不要求使用IE方式.
http://hq.sinajs.cn/list=sh601006返回的是一个字符串,如何获得这个字符串,如果非要使用IE,IE也最好隐藏,拜求了。
<head>
<title></title>
</head>
<body></body>
<script type="text/javascript" src="http://hq.sinajs.cn/list=sz000735" charset="gb2312"></script>
<script type="text/javascript">
var elements = hq_str_sz000735.split(",");
document.write("current price:" + elements[3]);
</script>
</html>请问如果用dephi如何得到该数据,不要求使用IE方式.
http://hq.sinajs.cn/list=sh601006返回的是一个字符串,如何获得这个字符串,如果非要使用IE,IE也最好隐藏,拜求了。
前者類似以下這樣:uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, OleCtrls, SHDocVw, ComCtrls, IdBaseComponent,
IdComponent, IdTCPConnection, IdTCPClient, IdHTTP,
MSHTML, ActiveX,comobj;procedure SetHtml(const WebBrowser:TWebBrowser; const Html: string);
var
Stream: IStream;
hHTMLText: HGLOBAL;
psi: IPersistStreamInit;
begin
if not Assigned(WebBrowser.Document) then Exit;hHTMLText := GlobalAlloc(GPTR, Length(Html) + 1);
if 0 = hHTMLText then RaiseLastWin32Error;CopyMemory(Pointer(hHTMLText),PChar(Html), Length(Html));OleCheck(CreateStreamOnHGlobal(hHTMLText, True, Stream));
try
OleCheck(WebBrowser.Document.QueryInterface(IPersistStreamInit, psi));
try
OleCheck(psi.InitNew);
OleCheck(psi.Load(Stream));
finally
psi := nil;
end;
finally
Stream := nil;
end;
end;function GetHtml(const WebBrowser:TWebBrowser): string;
const
BufSize = $ffff;
var
Size: Int64;
Stream: IStream;
hHTMLText: HGLOBAL;
psi: IPersistStreamInit;
begin
if not Assigned(WebBrowser.Document) then Exit;
OleCheck(WebBrowser.Document.QueryInterface(IPersistStreamInit, psi));try
//OleCheck(psi.GetSizeMax(Size));
hHTMLText := GlobalAlloc(GPTR, BufSize);
if 0 = hHTMLText then RaiseLastWin32Error;
OleCheck(CreateStreamOnHGlobal(hHTMLText,True, Stream)); try
OleCheck(psi.Save(Stream, False)); Size := StrLen(PChar(hHTMLText));
SetLength(Result, Size);
CopyMemory(PChar(Result), Pointer(hHTMLText),Size);
finally
Stream := nil;
end;
finally
psi := nil;
end;
end;procedure LoadBlankPage(WebBrowser:TWebBrowser);
var
URL: OleVariant;
begin
URL := 'about:blank';
WebBrowser.Navigate2(URL);
end;
function StringToWideString(const S: string; CodePage: Word): WideString;
var
InputLength, OutputLength: Integer;
begin
InputLength := Length(S);
OutputLength := MultiByteToWideChar(CodePage, 0, PChar(S), InputLength, nil, 0);
SetLength(Result, OutputLength);
MultiByteToWideChar(CodePage, 0, PChar(S), InputLength, PWideChar(Result), OutputLength);
end;
{按字节取出HTTP字节流}var
st : TMemoryStream;
ss : Tstringstream;
a : Array[0..1] of char; i : longword;
s : string;
begin
IdHTTP.HandleRedirects:=true;
IdHTTP.Request.ContentType:= 'application/x-www-form-urlencoded';
IdHTTP.Request.UserAgent:= 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322)';
IdHTTP.Request.SetHeaders;
try
st := TMemoryStream.Create ;
IdHttp.Get(weburl,st);
i := 0;
s := '';
st.Position := 0;
while i<st.Size do begin
st.Read(a,1);
s := s + inttostr(i+1) + '.#' + inttohex(ord(a[0]),2) + '('+ inttostr(ord(a[0])) +')' + ' ';
inc(i);
end;
richedit1.Text := s;
finally
st.Free ;
end;
end;{以下是一个读取文件ASCII码的过程}var
fs : TFileStream;
c : array[0..1] of char;
i : longword;
AC : string;
begin
if opendlg.Execute then begin
if not fileexists(opendlg.filename) then exit;
fs := TFileStream.Create(opendlg.filename,0);
fs.Position := 0;
i := 0 ;
while i < fs.size do begin
fs.Read(c,1);
inc(i);
ac := ac + inttostr(i) + '.' + inttohex(ord(c[0]),2) +'('+inttostr(ord(c[0]))+') ';
caption := inttostr(i) + '/' + inttostr(fs.size);
application.ProcessMessages ;
end;
fs.Free ;
memo1.Text := ac;
end;
end;
http://topic.csdn.net/u/20100825/21/94366d1e-78fa-46d4-8916-22b162b5334b.html?seed=337335081&r=67941258#r_67941258