Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/77.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/delphi/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Delphi中获取html表单和字符串字段_Html_Delphi_Dom_Ihtmldocument2 - Fatal编程技术网

在Delphi中获取html表单和字符串字段

在Delphi中获取html表单和字符串字段,html,delphi,dom,ihtmldocument2,Html,Delphi,Dom,Ihtmldocument2,我有一个系统,通过GET每隔1秒更新一次html中的系统数据,这个html可以有1-20个表单,需要采用所有表单并组装每个表单的查询字符串字段,我有一个函数可以做到这一点,问题是它需要比获取服务器html更长的时间,代码有什么问题?或者如何做的不同 procedure XThread.GetForms; var sTemp, xResF : String; FormItem, v: Variant; Field: Variant; J, q, i, contCampos, t

我有一个系统,通过GET每隔1秒更新一次html中的系统数据,这个html可以有1-20个表单,需要采用所有表单并组装每个表单的查询字符串字段,我有一个函数可以做到这一点,问题是它需要比获取服务器html更长的时间,代码有什么问题?或者如何做的不同

procedure XThread.GetForms;
var
  sTemp, xResF : String;
  FormItem, v: Variant;
  Field: Variant;
  J, q, i, contCampos,
  tmForm : Integer;
  IDocForm : IHTMLDocument2;
begin
 IDocForm := CreateComObject(Class_HTMLDOcument) as IHTMLDocument2;
 v := VarArrayCreate([0, 0], VarVariant);
 v[0] := strFormMAT; //string html
 IDocForm.Write(PSafeArray(System.TVarData(v).VArray));
 IDocForm.Close;

 tmForm := (IDocForm.all.tags('FORM') as IHTMLElementCollection).Length;
 SetLength(matFormsArray, 0); //matFormsArray = Global Array of Array
 SetLength(matFormsArray, tmForm);
 for q := 0 to tmForm -1 do
   begin
    SetLength(matFormsArray[q], 2);

    FormItem := (IDocForm.all.tags('FORM') as IHTMLElementCollection).item(q, 0);
    xResF := '';
    sTemp := FormItem.Name;
    contCampos := FormItem.Length;
     for j := 0 to contCampos - 1 do
      begin
        Field := FormItem.Item(j);
        xResF := xResF + Field.Name + '=' + Field.Value;
        if j < FormItem.Length - 1 then
          xResF := xResF + '&';
      end;

      matFormsArray[q, 0] := sTemp;
      matFormsArray[q, 1] := xResF;
   end;
end;
过程XThread.GetForms;
变量
sTemp,xResF:String;
FormItem,v:变体;
字段:变量;
J、 q,我,康坎波斯,
tmForm:整数;
IDocForm:IHTMLDocument2;
开始
IDocForm:=CreateComObject(类\u HTMLDOcument)作为IHTMLDDocument2;
v:=VarArrayCreate([0,0],varvarvariant);
v[0]:=strFormMAT//字符串html
Write(PSafeArray(System.TVarData(v.VArray));
IDocForm.Close;
tmForm:=(IDocForm.all.tags('FORM')作为IHTMLElementCollection)。长度;
设置长度(matFormsArray,0)//matFormsArray=数组的全局数组
设定长度(matFormsArray,tmForm);
对于q:=0到tmForm-1 do
开始
设定长度(matFormsArray[q],2);
FormItem:=(IDocForm.all.tags('FORM')作为IHTMlementCollection)。项(q,0);
xResF:='';
sTemp:=FormItem.Name;
contCampos:=模板长度;
对于j:=0到contCampos-1 do
开始
字段:=表单项(j);
xResF:=xResF+Field.Name+'='+Field.Value;
如果j
strFormMAT=

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>


<body>

 <form name="fprin" id="fprin">
   <input type="hidden" name="field11" value="value11"></input>
   <input type="hidden" name="field12" value="value12"></input>
   <input type="hidden" name="field13" value="value13"></input>
 </form>

 <table>
  <tr>
   <td>Title</td>
   <td>Title</td>
   <td>Title</td>
   <td>Title</td>
  </tr>

  <tr>
   <td>Value</td>
   <td>Value</td>
   <td>Value</td>
   <form name="xxx1" id="xxx1">
   <td>Value</td>
   <td>Value</td>
   <input type="hidden" name="field11" value="value11"></input>
   <input type="hidden" name="field12" value="value12"></input>
   <input type="hidden" name="field13" value="value13"></input>
   <input type="hidden" name="field14" value="value14"></input>
   </form>
  </tr>

  <tr>
   <td>Value</td>
   <td>Value</td>
   <td>Value</td>
   <form name="xxx2" id="xxx2">
   <td>Value</td>
   <td>Value</td>
   <input type="hidden" name="field21" value="value21"></input>
   <input type="hidden" name="field22" value="value22"></input>
   <input type="hidden" name="field23" value="value23"></input>
   <input type="hidden" name="field24" value="value24"></input>
   </form>
  </tr>

  <tr>
   <td>Value</td>
   <td>Value</td>
   <td>Value</td>
   <form name="xxx3" id="xxx3">
   <td>Value</td>
   <td>Value</td>
   <input type="hidden" name="field31" value="value31"></input>
   <input type="hidden" name="field32" value="value32"></input>
   <input type="hidden" name="field33" value="value33"></input>
   <input type="hidden" name="field34" value="value34"></input>
   </form>
  </tr>

  <tr>
   <td>Value</td>
   <td>Value</td>
   <td>Value</td>
   <form name="xxx4" id="xxx4">
   <td>Value</td>
   <td>Value</td>
   <input type="hidden" name="field41" value="value41"></input>
   <input type="hidden" name="field42" value="value42"></input>
   <input type="hidden" name="field43" value="value43"></input>
   <input type="hidden" name="field44" value="value44"></input>
   </form>
  </tr>

  <tr>
   <td>Value</td>
   <td>Value</td>
   <td>Value</td>
   <form name="xxx5" id="xxx5">
   <td>Value</td>
   <td>Value</td>
   <input type="hidden" name="field51" value="value51"></input>
   <input type="hidden" name="field52" value="value52"></input>
   <input type="hidden" name="field53" value="value53"></input>
   <input type="hidden" name="field54" value="value54"></input>
   </form>
  </tr>

  <tr>
   <td>Value</td>
   <td>Value</td>
   <td>Value</td>
   <form name="xxx6" id="xxx6">
   <td>Value</td>
   <td>Value</td>
   <input type="hidden" name="field61" value="value61"></input>
   <input type="hidden" name="field62" value="value62"></input>
   <input type="hidden" name="field63" value="value63"></input>
   <input type="hidden" name="field64" value="value64"></input>
   </form>
  </tr>


 </table>

</body>

</html>

无标题文件
标题
标题
标题
标题
价值
价值
价值
价值
价值
价值
价值
价值
价值
价值
价值
价值
价值
价值
价值
价值
价值
价值
价值
价值
价值
价值
价值
价值
价值
价值
价值
价值
价值
价值
我使用
Synchronize(GetForms)在线程内进行过程调用甚至崩溃和减速


我的问题是没有得到html,它已经启动并运行了,问题是提取html的形式,这个过程很慢

你的问题并不完全清楚你想做什么,但是看起来您应该研究一种不同的技术来使用,而不是加载此自定义HTML代码的HTMLDocument来完成此工作


如果需要使用由字段和值组成的查询字符串调用某个URL,则应查看
TIdHTTP
或(或)。

将解析器过程带到线程类之外。将其设置为tform的本地过程,并使用方法“Synchronize”调用它。您使用的是基于DOM的解析器,由于它必须解析HTML并在内存中为每个HTML元素创建一个对象树,因此速度天生就很慢。但更重要的是,调用
IDocForm.all.tags('FORM')
的次数太多了—一次是为了发现
元素的数量,然后在每次循环迭代中再次调用。不要那样做,这是浪费开销。调用它一次,并将所得的<代码> IHTMLeltMeCytos/Cuff>保存到变量中,然后根据需要调用该变量的“代码”>代码(<)/代码>。在任何情况下,您都在HTML中寻找特定的东西,因此您应该考虑只删除DOM解析器,而使用简单的子字符串搜索+提取操作来代替。那会快得多。或者至少切换到基于SAX的HTML解析器,或者更好地切换到基于阅读器的HTML解析器,而不是基于DOM的解析器。可悲的是,我不知道任何免费的-只是这个付费的-dihtmlparsertanks的家伙,我会寻找另一种方法来使用html,真的它是驱动速度最慢的应用程序,在不同的地方使用如果有人有任何提示,谢谢!您好,我的问题不是获取html,它已经启动并运行了,问题是提取html的形式,这个过程很慢。我添加了一个html代码模型,用于提取必要的形式和字段。我仍然完全不清楚您要用它做什么。更糟糕的是,现在看来我错了,以为你在提交表格。