首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > .NET >

批量html转text的有关问题

2013-01-06 
批量html转text的问题本帖最后由 hncdllyz 于 2012-11-16 12:26:15 编辑批量html转text一个按钮、一个DEMO、

批量html转text的问题
本帖最后由 hncdllyz 于 2012-11-16 12:26:15 编辑 批量html转text
一个按钮、一个DEMO、一个WebBrowser1(internet页)
procedure TForm1.Button1Click(Sender: TObject);
begin
for i=0 to x do begin
    s1 := GetCurrentDir + '\Article' + inttostr(i) + '.html';
    s2 := GetCurrentDir + '\Article' + inttostr(i) + '.txt';
    WebBrowser1.Navigate(s1);//此句会触发下面的例程,如果循环一次正常,循环多次,因为同步的问题得不到正确结果
    while WebBrowser1.Busy do Application.ProcessMessages;
end;
end;
procedure TForm1.WebBrowser1DocumentComplete(Sender: TObject; const pDisp: ispatch; var URL: OleVariant);
begin
    Memo2.Lines.Add(IHtmlDocument2(WebBrowser1.Document).Body.outerText);
    memo2.Lines.SaveToFile(s2);
end;
我该咋办?
[解决办法]
一个DEMO?
[解决办法]


procedure TForm1.Button1Click(Sender: TObject);
var
  V : Variant;
begin
  WebBrowser1.Navigate('about:blank');
  while WebBrowser1.Tag=0 do Application.ProcessMessages;
  V := WebBrowser1.Document;

  Memo1.Lines.LoadFromFile('C:\1.html');
  V.body.innerHTML := Memo1.Text;
  Memo3.Text := V.body.innerText;

  Memo2.Lines.LoadFromFile('C:\2.html');
  V.body.innerHTML := Memo2.Text;
  Memo4.Text := V.body.innerText;

  //清除WebBrowser
  V.body.innerHTML := '<html></html>';
end;

procedure TForm1.WebBrowser1DocumentComplete(Sender: TObject;
  const pDisp: IDispatch; var URL: OleVariant);
begin
  TComponent(Sender).Tag := 1;
end;

热点排行