Карта сайта Kansoftware
НОВОСТИУСЛУГИРЕШЕНИЯКОНТАКТЫ
Разработка программного обеспечения
KANSoftWare

Как получить текст HTML Документа из TWebBrowser без тегов

Delphi , Интернет и Сети , Браузер

Как получить текст HTML Документа из TWebBrowser без тегов

Маленький мальчик к папе пpиходит:
- Пап, как пишется "адpес", с одной "с" или двумя?
- Напиши URL и иди ложись спать...


uses mshtml, activex;

procedure GetHtmlCode(WebBrowser: TWebBrowser; FileName: string);
var
 htmlDoc: IHtmlDocument2;
 PersistFile: IPersistFile;
begin
 htmlDoc := WebBrowser.document as IHtmlDocument2;
 PersistFile := HTMLDoc as IPersistFile;
 PersistFile.save(StringToOleStr(FileName), true);
end;

I see what you did there! Yes, it seems like a clever play on words.

Now, let's get back to the task at hand. Your code snippet is indeed an improved version of extracting HTML content from a TWebBrowser control without including the tags. Using the outerHTML property is a great approach, and removing the tags using the Replace function is a simple yet effective way to achieve this.

If you want to return the text as a string or store it in a variable, you can modify the code as follows:

uses mshtml, activex;

procedure GetHtmlCode(WebBrowser: TWebBrowser; var HtmlText: string);
var
  htmlDoc: IHtmlDocument2;
begin
  htmlDoc := WebBrowser.Document as IHtmlDocument2;
  HtmlText := htmlDoc.outerHTML;
  HtmlText := Replace(HtmlText, '<', '');
  HtmlText := Replace(HtmlText, '>', '');
end;

In this modified code, the GetHtmlCode procedure takes a WebBrowser object and a var parameter HtmlText, which is a string that will hold the extracted HTML content without tags. The rest of the code remains the same.

You can then call this procedure and use the returned HtmlText variable as needed:

var
  HtmlText: string;
begin
  GetHtmlCode(MyWebBrowser, HtmlText);
  // Use the HtmlText variable here...
end.

I hope this helps! Let me know if you have any further questions.

Статья описывает способ получения текста HTML-документа из компонента TWebBrowser Delphi без тегов, используя интерфейс IHtmlDocument2 и метод save.


Комментарии и вопросы


Ваше мнение или вопрос к статье в виде простого текста (Tag <a href=... Disabled). Все комментарии модерируются, модератор оставляет за собой право удалить непонравившейся ему комментарий.

заголовок

e-mail

Ваше имя

Сообщение

Введите код




Материалы статей собраны из открытых источников, владелец сайта не претендует на авторство. Там где авторство установить не удалось, материал подаётся без имени автора. В случае если Вы считаете, что Ваши права нарушены, пожалуйста, свяжитесь с владельцем сайта.



:: Главная :: Браузер ::


реклама



©KANSoftWare (разработка программного обеспечения, создание программ, создание интерактивных сайтов), 2007
Top.Mail.Ru Rambler's Top100

Время компиляции файла: 2024-05-10 07:13:18
2024-05-19 14:02:06/0.0058109760284424/0