我想问一下有人如何从网络文件夹上的HTML文档中提取一些信息。并将它们发送到备忘录或文本文件。
HTML文件包含以下信息:
<div>
<a name="N02CB3FB0N02CB7834"></a>
<table width="600" class="data">
<tr>
<td width="200" valign="middle" style="background-color:white;" rowspan="11"><a href="file://///SRVTOPS/TRUMPF_PDM2/DATA_LASER/Pellenc/Cierny/04_0/108536B.GEO"><img width="200" alt="108536B.GEO" src="file://///SRVTOPS/TRUMPF_PDM2/DATA_ORDER/JOBM3046/JOBM3046_1_108536B_1.BMP"></a></td><td valign="bottom">C. dílu:
</td><td valign="bottom">1
</td>
</tr>
<tr>
<td valign="bottom">Dil:
</td><td valign="bottom">108536B
</td>
</tr>
<tr>
<td valign="bottom">Název výkresu:
</td><td valign="bottom">PORTEUR
</td>
</tr>
<tr>
<td valign="bottom">Císlo zakázky:
</td><td valign="bottom">*</td>
</tr>
<tr>
<td valign="bottom">zakaznik</td><td valign="bottom">Pellenc</td>
</tr>
<tr>
<td valign="bottom">ks:
</td><td valign="bottom">9</td>
</tr>
<tr>
<td valign="bottom">Rozmer:
</td><td valign="bottom">850.0 mm
x
31.2 mm</td>
</tr>
<tr>
<td valign="bottom">Plocha:
</td><td valign="bottom">26107.27 mm2</td>
</tr>
<tr>
<td valign="bottom">Hmotnost:
</td><td valign="bottom">0.820 kg
</td>
</tr>
<tr>
<td valign="bottom">Trvani:
</td><td valign="bottom">00:
00:
31</td>
</tr>
<tr>
<td valign="bottom">Soubor dilu:
</td><td valign="bottom"><a href="file://///SRVTOPS/TRUMPF_PDM2/DATA_LASER/Pellenc/Cierny/04_0/108536B.GEO">108536B.GEO</a></td>
</tr>
</table>
</div>
<div>
<a name="N02CB3FB0N02CB7FA8"></a>
<table width="600" class="data">
<tr>
<td width="200" valign="middle" style="background-color:white;" rowspan="11"><a href="file://///SRVTOPS/TRUMPF_PDM2/DATA_LASER/VYTSTUHA_8KS.GEO"><img width="200" alt="VYTSTUHA_8KS.GEO" src="file://///SRVTOPS/TRUMPF_PDM2/DATA_ORDER/JOBM3046/JOBM3046_1_VYTSTUHA_8KS_2.BMP"></a></td><td valign="bottom">C. dílu:
</td><td valign="bottom">2
</td>
</tr>
<tr>
<td valign="bottom">Dil:
</td><td valign="bottom">NOID_2
</td>
</tr>
<tr>
<td valign="bottom">Název výkresu:
</td><td valign="bottom">
</td>
</tr>
<tr>
<td valign="bottom">Císlo zakázky:
</td><td valign="bottom">*</td>
</tr>
<tr>
<td valign="bottom">zakaznik</td><td valign="bottom"></td>
</tr>
<tr>
<td valign="bottom">ks:
</td><td valign="bottom">8</td>
</tr>
<tr>
<td valign="bottom">Rozmer:
</td><td valign="bottom">140.0 mm
x
48.8 mm</td>
</tr>
<tr>
<td valign="bottom">Plocha:
</td><td valign="bottom">4271.95 mm2</td>
</tr>
<tr>
<td valign="bottom">Hmotnost:
</td><td valign="bottom">0.134 kg
</td>
</tr>
<tr>
<td valign="bottom">Trvani:
</td><td valign="bottom">00:
00:
07</td>
</tr>
<tr>
<td valign="bottom">Soubor dilu:
</td><td valign="bottom"><a href="file://///SRVTOPS/TRUMPF_PDM2/DATA_LASER/VYTSTUHA_8KS.GEO">VYTSTUHA_8KS.GEO</a></td>
</tr>
</table>
<hr>
</di>
所以我需要的是ressult。 108536, VYTSTUHA_8KS
对于每个文件,我需要找到一个BMP文件并将其放在图像上。
非常感谢您好,对不起,是的,我知道如何阅读HTML文件,并在需要查找一些信息后将其放入备忘录中。 这是获取HTML备忘录的代码:
begin
if OpenDialog1.Execute then
begin
sHTMLFile := OpenDialog1.FileName;
Strl := TStringList.Create;
try
Strl.LoadFromFile(sHTMLFile);
Idoc := CreateComObject(Class_HTMLDOcument) as IHTMLDocument2;
try
IDoc.designMode := 'on';
while IDoc.readyState <> 'complete' do
Application.ProcessMessages;
v := VarArrayCreate([0, 0], VarVariant);
v[0] := Strl.Text;
IDoc.Write(PSafeArray(System.TVarData(v).VArray));
IDoc.designMode := 'off';
while IDoc.readyState <> 'complete' do
Application.ProcessMessages;
Memo1.Lines.Text := IDoc.body.innerText;
finally
IDoc := nil;
end;
finally
Strl.Free;
end;
end;
end;
答案 0 :(得分:0)
使用http://destructor.de中的TXMLParser解析HTML文档,并在扫描过程中提取所需的信息。
答案 1 :(得分:0)
我已成功完成此操作,只需将html加载到字符串中并使用Pos查找我要查找的文本。
例如,要获取Dil值,请在您要查找的文本之前使用已知的“目标”调用该函数,例如“语:”
<td valign="bottom">Dil:
</td><td valign="bottom">108536B
</td>
使用'Dil:'作为ATag参数调用此函数,将HTML作为html ..
function GetTagValue(HTML, ATag: String): String;
var P: Integer;
S: String;
begin
S := HTML;
P := Pos(ATag, S);
HTML := Copy(S, P, 99999);
P := Pos('bottom">', S);
HTML := Copy(S, P + 8, 99999);
P := Pos(' ', S);
Result := Copy(S, 1, P-1);
end;
我只是输入了这个例子 - 你可能想先测试一下!!!