问题来源: http://www.cnblogs.com/del/archive/2008/04/02/1131232.html#1133889
答案: WebBrowser1.OleObject.Document.ParentWindow.变量名;
譬如有这样一个页面(lancernig 举的例子), 如何提取其中的 pvs 呢:
<html>
<head>
<title>测试页</title>
<script language="javascript" type="text/javascript">
var smoneyval = "0";
var cival = "0";
//var ssum = 0;
var smoneys = "0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0" ;
var cis = "0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0";
var pvs = "140.74,142.51,106.64,86.39,77.71,52.48,38.90,28.76,25.59,19.23,17.23,14.24,12.21,12.00,12.33,12.33,13.55,14.28,19.80,24.34,32.21,38.80,46.47,74.96,94.80,117.13,174.36,269.35";
var smoneys_Array = smoneys.split(",");
var cis_Array = cis.split(",");
var pvs_Array = pvs.split(",");
</script>
</head>
<body>
...
</body>
</html>
假定是把页面保存在 'c:\temp\test.htm', 测试代码如下:
答案: WebBrowser1.OleObject.Document.ParentWindow.变量名;
譬如有这样一个页面(lancernig 举的例子), 如何提取其中的 pvs 呢:
假定是把页面保存在 'c:\temp\test.htm', 测试代码如下:
unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, OleCtrls, SHDocVw; type TForm1 = class(TForm) WebBrowser1: TWebBrowser; Button1: TButton; procedure FormCreate(Sender: TObject); procedure Button1Click(Sender: TObject); end; var Form1: TForm1; implementation {$R *.dfm} procedure TForm1.FormCreate(Sender: TObject); begin WebBrowser1.Navigate('c:\temp\test.htm'); end; procedure TForm1.Button1Click(Sender: TObject); var s: string; begin {提取 smoneys} s := WebBrowser1.OleObject.Document.ParentWindow.smoneys; ShowMessage(s); {提取 pvs} s := WebBrowser1.OleObject.Document.ParentWindow.pvs; ShowMessage(s); end; end.