[Qt-interest] how to find all images used by webpage

Sean Harmer sean.harmer at maps-technology.com
Thu Jun 17 10:24:52 CEST 2010


Hi,

On Thursday 17 June 2010 02:43:21 Richard Baron Penman wrote:
> hello,
> 
> I am using QWebView to load a webpage. How can I find a list of the image
> URLs used by a webpage, including background images referenced in external
> CSS?
> 
> One possibility is to evaluateJavaScript:
> webView.page()->mainFrame()->evaluateJavaScript("document.getElementsByTagN
> ame(\"img\");");
> 
> But that feels messy and would miss CSS images anyway.
> Any ideas?

One possible approach would be to use a customised QNetworkAccessManager 
(QNAM) subclass that logs all image requests. To get an idea on how to do this 
see the following blog entries:

http://www.kdedevelopers.org/node/4210
http://www.kdedevelopers.org/node/4237

Essentially all you have to do is to inherit your own class from QNAM and 
override the createRequest() function. In your specialised version look at the 
contents of the request, decide if it is requesting an image or not and then 
log it.

HTH,

Sean



More information about the Qt-interest-old mailing list