Saving images in the WebView as files

Post your Gambas programming questions here.
Post Reply
bazzvn
Posts: 18
Joined: Wednesday 22nd February 2017 11:06am
Location: Vietnam

Saving images in the WebView as files

Post by bazzvn »

In Firefox, Right-Clicking on an image will usually allow one to save the image to a local file. I am trying to do the same sort of thing from web pages displayed in a Qt WebView.
It is not too difficult to extract the link to the image source from the WebView, for example, "https://www.quantamagazine.org/wp-content/uploads/2017/03/EvoHorse_1K.jpg", but I don't know how to locate or specify the path to the source file within this link so that the file can be copied to a local folder.
I would be grateful for any suggestions.
bazzvn
User avatar
jornmo
Site Admin
Posts: 224
Joined: Wednesday 21st September 2016 1:19pm
Location: Norway

Re: Saving images in the WebView as files

Post by jornmo »

If you are asking how to save it? Then look at this: http://gambaswiki.org/wiki/comp/gb.net.curl/httpclient

If you are asking how to extract the filename from the URL, try this:
Dim sFileName As String
Dim sURL As String = "someURL"
sFileName = Split(sURL, "/").Reverse()[0]
bazzvn
Posts: 18
Joined: Wednesday 22nd February 2017 11:06am
Location: Vietnam

Re: Saving images in the WebView as files

Post by bazzvn »

Thank you Jornmo. It was the former, how to save the file. I never thought to look at the gb.net component, but the wiki link you posted looks like it will solve my problem. Much appreciated.
bazzvn
User avatar
jornmo
Site Admin
Posts: 224
Joined: Wednesday 21st September 2016 1:19pm
Location: Norway

Re: Saving images in the WebView as files

Post by jornmo »

You may also find that gb.xml.html:

http://gambaswiki.org/wiki/comp/gb.xml.html/

is a good alternative to the webkit component for web scraping :)

I just scraped 66 pages in 5-10 seconds here the other day with this method myself.
Post Reply