Solved

WebBrowser outerHTML and '??????'

Posted on 2010-11-18
7
1,082 Views
Last Modified: 2012-05-10
Hi,

I have problem with getting source from webbrowser. Some charakters are replaced with question marks. Iam using Delphi 7

0
Comment
Question by:lavitz
  • 3
  • 3
7 Comments
 
LVL 9

Expert Comment

by:Mahdi78
ID: 34163262
Try this

Memo1.Text := WebBrowser1.OleObject.Document.documentElement.innerHTML;
0
 
LVL 24

Expert Comment

by:jimyX
ID: 34163449
What is the code the you are using ?

Here is the right way to do that:
http://delphi.about.com/od/adptips2005/qt/webbrowserhtml.htm

uses mshtml;

var
    iall : IHTMLElement;
begin
   if Assigned(WebBrowser1.Document) then
   begin
     iall := (WebBrowser1.Document AS IHTMLDocument2).body;

     while iall.parentElement <> nil do
     begin
       iall := iall.parentElement;
     end;
     memo1.Text := iall.outerHTML;
   end;
end;

Open in new window

0
 

Author Comment

by:lavitz
ID: 34166506
I have made simple test on new project.
WebBrowser navigates prepared html file, and show it in tmemo.
Code is like jimyX: described.
And unfortunately i still have ????? in memo.

There is nothing  i could do wrong.

html file that i have loaded have charset=utf-8 and characters iam wrote  was cyrillic.
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 24

Expert Comment

by:jimyX
ID: 34167182
Set your memo font to "Arial Unicode MS".
0
 

Author Comment

by:lavitz
ID: 34170899
didnt work.

html code (in place of ??????? is cyrillic, i dont know why EE dosnt save it)
 
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body>
¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿<br>
¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿<br>
¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿gfd<br>
</body></html>

Open in new window


delphi code
 
procedure TForm1.Button2Click(Sender: TObject);
var
    iall : IHTMLElement;
begin
   if Assigned(WebBrowser1.Document) then
   begin
     iall := (WebBrowser1.Document AS IHTMLDocument2).body;

     while iall.parentElement <> nil do
     begin
       iall := iall.parentElement;
     end;
     memo1.Text := iall.outerHTML;
   end;
end;

Open in new window

0
 
LVL 24

Accepted Solution

by:
jimyX earned 500 total points
ID: 34171035
That works if you write directly on the memo from the keyboard (I tried Chinese on my PC which is not configured to Chinese language and it worked).

Anyway let's get the string decoded using UTF8Decode:
memo1.Text := UTF8Decode(iall.outerHTML);
or,
memo1.Text := Utf8ToAnsi(iall.outerHTML);

If also not working (and that's because Delphi 7 default components do not support Unicode/UTF-8) you have to use another components that support Unicode, such as:

http://www.tntware.com/tntmpd/downloads/p/11083.aspx
or
http://www.tmssoftware.com/site/tmsuni.asp
0
 

Author Closing Comment

by:lavitz
ID: 34171768
It works with different components(tnt)
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now