wxHtmlWindow and online images ?

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
xtn
In need of some credit
In need of some credit
Posts: 5
Joined: Wed Sep 21, 2005 1:56 pm

wxHtmlWindow and online images ?

Post by xtn »

My probleme is simple, images On web pages I don't load doesn't appear
I added in my wxApp::OnInit the function

Code: Select all

wxInitAllImageHandlers(); 
as mentionned in the documentation.

My linked libraries are the following :
wxmsw26_html, wxmsw26_core, wxbase26, wxbase26_net, wxexpat, wxtiff, wxjpeg, wxpng, wxzlib

Take a look at the code ( I removed error's tests ) :

Code: Select all

    wxHtmlWindow *htmlban = new wxHtmlWindow(MainPanel, -1, wxDefaultPosition, wxDefaultSize, 0, "htmlpage");

    mainflexbar->Add( htmlban, 0, /*wxGROW|*/wxALIGN_CENTER_VERTICAL|wxALL, 5 );

    wxURL url("http://www.google.com");
    wxInputStream *data = url.GetInputStream(); 
    wxFile fTest(".tmp.htm", wxFile::write );
    wxFileOutputStream streamout( fTest ); 
    data->Read(streamout);
    fTest.Close();
    htmlban->LoadPage(".tmp.html");
We have a nice google homepage downloaded... without any images :/

How can I handle that ?[/code]
priyank_bolia
wxWorld Domination!
wxWorld Domination!
Posts: 1339
Joined: Wed Aug 03, 2005 8:10 am
Location: BANGALORE, INDIA
Contact:

Post by priyank_bolia »

htmlban->LoadPage("www.google.com");

when you save it on disk, the path of the images in the folder is relative, so it won't load, when you laod priyank.in,you will see the images because the paths are complete.
xtn
In need of some credit
In need of some credit
Posts: 5
Joined: Wed Sep 21, 2005 1:56 pm

Post by xtn »

hmm I am sorry but I tried with "http://priyank.in/get.php", and this is the same, I get the page text, but still not the images ( there is image error icons instead of the image )
phlox81
wxWorld Domination!
wxWorld Domination!
Posts: 1387
Joined: Thu Aug 18, 2005 7:49 pm
Location: Germany
Contact:

Re: wxHtmlWindow and online images ?

Post by phlox81 »

xtn wrote: wxFile fTest(".tmp.htm", wxFile::write );
htmlban->LoadPage(".tmp.html");
[/code]
is this just an error ?
What are the imagetags at the file you save ?
Are they 'local' (../img/test.jpg) or global (http://myurl.com/img/test.jpg) ?
xtn
In need of some credit
In need of some credit
Posts: 5
Joined: Wed Sep 21, 2005 1:56 pm

Post by xtn »

.tmp.htm is not an error, I put the dot to automatically hide the file under a linux like system.

The images paths from the URL "http://priyank.in/get.php" are all global ( As i said to us at the begining )
phlox81
wxWorld Domination!
wxWorld Domination!
Posts: 1387
Joined: Thu Aug 18, 2005 7:49 pm
Location: Germany
Contact:

Post by phlox81 »

xtn wrote:.tmp.htm is not an error, I put the dot to automatically hide the file under a linux like system.

The images paths from the URL "http://priyank.in/get.php" are all global ( As i said to us at the begining )
you save *.htm and load *.html ...

Is there some kind of Firewall or something preventing the img Download ?
May be the control itself ?

Did you try loadFile ?
Last edited by phlox81 on Wed Sep 21, 2005 3:08 pm, edited 2 times in total.
priyank_bolia
wxWorld Domination!
wxWorld Domination!
Posts: 1339
Joined: Wed Aug 03, 2005 8:10 am
Location: BANGALORE, INDIA
Contact:

Post by priyank_bolia »

htmlban->LoadPage("http://www.priyank.in/welcome.php");

the problem is images in the google.com have relative paths, not absolute. So you have to download the images also and put in the images folder under which you save the file.
priyank_bolia
wxWorld Domination!
wxWorld Domination!
Posts: 1339
Joined: Wed Aug 03, 2005 8:10 am
Location: BANGALORE, INDIA
Contact:

Post by priyank_bolia »

Also have a image in the same folder and try to load that say:
htmlban->LoadPage("test.jpg");
then also check that whether:
htmlban->LoadPage("http://www.priyank.in/images/priyank.jpg");
is working or not?
xtn
In need of some credit
In need of some credit
Posts: 5
Joined: Wed Sep 21, 2005 1:56 pm

Post by xtn »

priyank_bolia wrote: the problem is images in the google.com have relative paths, not absolute. So you have to download the images also and put in the images folder under which you save the file.
Ok, but in that way how to get the images ?

But, Priyank, problem is that I don't see the images with your site which as global paths to images ... ( the control displays a big error icon instead )

Is my code really correct ?

I have no firewall neither proxy that could block the application
phlox81 wrote: you save *.htm and load *.html
Yes a little copy/paste error :)
Vaulter
Earned a small fee
Earned a small fee
Posts: 19
Joined: Thu Jun 30, 2005 7:49 am
Location: Russia
Contact:

Post by Vaulter »

xtn wrote: Ok, but in that way how to get the images ?
at first, load to string tmp.html (htm)
then parse it by regex something like that:

Code: Select all

<img[^>src]+src=(('|")?[^'"\s]*('|")?)
then for all Matches(1) download images and save
priyank_bolia
wxWorld Domination!
wxWorld Domination!
Posts: 1339
Joined: Wed Aug 03, 2005 8:10 am
Location: BANGALORE, INDIA
Contact:

Post by priyank_bolia »

Ok, I check it, the problem is that htmlwindow can not directly download the images, so you have to manually download it and put in a local folder and changes all the absolute path in the html to some path on the current hard drive where the image resides. To download images you can use Vaulter method to scan for the images and then you have to convert the relative paths to absolute URL then download them using wxURL, after that save them to the local disk.

Or

Try with wxMozilla... it more easier.
xtn
In need of some credit
In need of some credit
Posts: 5
Joined: Wed Sep 21, 2005 1:56 pm

Post by xtn »

this works very well when I parse the page and download for the images.

Thank you all :D
Post Reply