WebBrowser sample

Discussions related to Visual Prolog
User avatar
Tonton Luc
VIP Member
Posts: 814
Joined: 16 Oct 2001 23:01

WebBrowser sample

Unread post by Tonton Luc » 13 Jul 2006 9:26

Hey,

How to recover dynamically all the text of an html page displaying by WebBrowser sample ?

User avatar
Thomas Linder Puls
VIP Member
Posts: 2438
Joined: 28 Feb 2000 0:01

Unread post by Thomas Linder Puls » 13 Jul 2006 13:32

This is relatively difficult. The webBrowser is actually a shell that host other controls, when it is displaying HTML code it hosts the MSHTML component, and it is through this you can obtain the displayed text. But I will warn you, the importer cannot deal with all MSHTML and if you try you will get several modules that are more than 200.000 lines. You should probably just import the IHTMLDocument2 interface.

The method is something like this:
  • Ask for the "document" on the webBrowser
  • (in reality you should wait for the document loaded event before asking for the document, but in practice it will most likely work without).
  • Query the resulting interface for the IHTMLDocument2 interface
  • Call toString on this interface
Let me hear if you succeed ;-).

When Vip7 is released I plan to release a little webBrowser experiment project I have. This project loads a string into the webControl something which sounds incredible simple, but in reality it is rather complex.
Regards Thomas Linder Puls
PDC

Gildas Menier
VIP Member
Posts: 78
Joined: 8 Jun 2004 23:01

Unread post by Gildas Menier » 18 Jul 2006 9:37

(Just my 2 cents)

It depends on what you are trying to acheive : you already can use the (great) lib provided by Jan de Lint, or mine (vp_web) that both provide a way to get a web page source given its URL. If you want to use the IE control, you may use the same lib with the URL you retrieve from your control : the page should already be in cache so you should get what you want with no extra cost.

As for MSHTML, it is possible to avoid the 200000 lines : you only have to import the IHTMLDocument2 Interface and patch the importer code (that is indeed incorrect) - then you have to play with safearray from COM. I doubt that the tostring method provided by the COM may be of use, since you may only have access to a tree of objects (you may only get the string [object] for instance, instead of the HTMl code). But I use getbody and getInnerHTML with success. As for the writing in the control, it is easy when you use the write and writeln method provided by the COM on IHTMLDocument2. I never succeed to call these from Visual Prolog (some strange Memory access issue with safearray) but a small C/C++ lib wrapper does it.

Regards

Gildas

User avatar
Tonton Luc
VIP Member
Posts: 814
Joined: 16 Oct 2001 23:01

Unread post by Tonton Luc » 19 Jul 2006 6:58

For exemple, when you are going to the site of Mercedes, I would like to recover the technical caracteristique of one or 2 cars. Theese caracteristique are not appeard in the source of their html pages. I think they are displaying by a flow of datas...

User avatar
Tonton Luc
VIP Member
Posts: 814
Joined: 16 Oct 2001 23:01

Unread post by Tonton Luc » 19 Jul 2006 10:38

An other question : how to make a SendEvent from the taskwindow to BrowserWindow ?
Here is the code of the task :

Code: Select all

predicates     onCreate : window::showListener. clauses     onCreate(_, _CreationData):-         messageWin := messageForm::new(This),         messageWin:show(),         BW=browserWindow::new(This),         BW:show(),         _ = vpi::winSendEvent(??? onButtonGo ???    
...to start the navigation automatically when the browser open.

Yuri Ilyin
Posts: 9
Joined: 3 May 2000 23:01

Unread post by Yuri Ilyin » 19 Jul 2006 11:17

Do you have a sample in another language to send such event?

Anyway you can call the appropriate predicate to locate url instead of sending the event.
regards Yuri.

User avatar
Thomas Linder Puls
VIP Member
Posts: 2438
Joined: 28 Feb 2000 0:01

Unread post by Thomas Linder Puls » 19 Jul 2006 11:27

You should not send events to the window; you should ask the window to navigate instead, like in this predicate:

Code: Select all

predicates     onButtonGo : button::clickResponder. clauses     onButtonGo(_Source) = button::defaultAction :-         URL=editURL:getText(),         browser:navigate(URL,             comDomains::unsigned(0x0),             comDomains::null,             comDomains::null,             comDomains::null).
Regards Thomas Linder Puls
PDC

User avatar
Tonton Luc
VIP Member
Posts: 814
Joined: 16 Oct 2001 23:01

Unread post by Tonton Luc » 19 Jul 2006 11:28

Do you have a sample in another language to send such event ? => I don't understand what you mean :shock:

Anyway you can call the appropriate predicate to locate url instead of sending the event. => ok, easy.

User avatar
Tonton Luc
VIP Member
Posts: 814
Joined: 16 Oct 2001 23:01

Unread post by Tonton Luc » 3 Aug 2009 8:50

Hi,
I try to get HTML page and convert it in txt using webBrowser sample in VP7.2. I add a new Com package msHTML in my project and I try to "Query the resulting interface for the IHTMLDocument2 interface" as Thomas proposal in preceding post.
What's wrong in this code :

Code: Select all

facts     browser : iWebBrowser2_import := uncheckedConvert(iWebBrowser2_import,null).     htmlDoc : iHTMLDocument2_import := uncheckedConvert(iHTMLDocument2_import,null).   clauses     onButtonGoClick(_Source) = button::defaultAction :-         Doc = comInterface::new(browser:get_Document(), comMemory::release()),         htmlDoc := iHTMLDocument2_import::newQuery(Doc),         htmlDoc:writeln(Array),         htmlDoc:close().
error c229: Undeclared identifier 'iHTMLDocument2_import::newQuery/1->'

User avatar
Thomas Linder Puls
VIP Member
Posts: 2438
Joined: 28 Feb 2000 0:01

Unread post by Thomas Linder Puls » 3 Aug 2009 18:51

That error is caused by an unfortunate design from my side :oops:.

The problem is that the class and interface iHTMLDocument2_import are in two different packages:
  • the interface is in mshtml\interface
  • the class is in mshtml\implement
This is very bad for the automatic handling of include statements.

You have an include statement for mshtml\interface\mshtml_interface.ph, but it should be mshtml\import\mshtml_import.ph.
Regards Thomas Linder Puls
PDC

User avatar
Tonton Luc
VIP Member
Posts: 814
Joined: 16 Oct 2001 23:01

Unread post by Tonton Luc » 4 Aug 2009 9:00

Ok, the code works fine now. Many tks.
I try to recover all links value in an HTML page without succes. After recover the number of links in my page using get_Length(), what code I need to use to recover the value of each links ?

Code: Select all

    facts     browser : iWebBrowser2_import := uncheckedConvert(iWebBrowser2_import,null).     htmlDoc : iHTMLDocument2_import := uncheckedConvert(iHTMLDocument2_import,null).   clauses onButtonGoClick(_Source) = button::defaultAction :-         Doc = comInterface::new(browser:get_Document(), comMemory::release()),         htmlDoc := iHTMLDocument2_import::newQuery(Doc),         Links = iHTMLElementCollection_import::newQuery(htmlDoc:get_Links()),         NbLinks = Links:get_Length(),

daveplummermd
VIP Member
Posts: 88
Joined: 18 Jul 2006 17:18

Unread post by daveplummermd » 27 Dec 2012 9:37

guys

one of you seems likely to have finally solved this. but the advice above appears to apply to a version prior to 7.4
i have carefully studied all of the posts that you have referred me to.
i am unclear how to import mshtml , or subset thereof.

ultimately, i am simply trying to retrieve the html of a document loaded into the web browser control.

do either of you had any further advice or care to share any specific successful example?

Stumped....

thanks in advance

Dave Plummer
Dave Plummer

User avatar
Tonton Luc
VIP Member
Posts: 814
Joined: 16 Oct 2001 23:01

Unread post by Tonton Luc » 27 Dec 2012 10:01

Hi,

I've only a VP 7.2 sample and it works fine.
If you are interested, I can post it here.

daveplummermd
VIP Member
Posts: 88
Joined: 18 Jul 2006 17:18

Unread post by daveplummermd » 27 Dec 2012 12:15

yes. i would very much appreciate that.
thanks so much

dave plummer
Dave Plummer

User avatar
Tonton Luc
VIP Member
Posts: 814
Joined: 16 Oct 2001 23:01

Unread post by Tonton Luc » 27 Dec 2012 14:16

Hi,

You can download it from this adress : http://jdklog.pagesperso-orange.fr/Pour ... rowser.zip
...because we only attach small size on this post.
After to start the application on your machine, just need to clic on the button Go and see the result on message window.

Post Reply