PDA

View Full Version : Get images from a QWebView or QWebPage



redneon
18th January 2010, 12:54
I'm trying to write a small image ripping tool for the Circuit Tokei section of the Bijin Tokei website (http://www.bijint.com/cc/). Please don't judge me :)

My plan is to store off the images so I can use them in a small clock application for my Google sidebar thing. Now, because there is a common theme among the names of the URL you'd think this would be easy. All image URLs are similar to this...

http://www.bijint.com/assets/pict/cc/590x450/1742.jpg

..where 1742 is the the current time of day. When I first started this I thought "Great!" I can just create a program which cycles through all the minutes of the day and calls a simple download on them. Problem is, Bijin Tokei have done a lot of work to stop people from doing exactly what I'm trying to do. First of all, you're forbidden to access the image unless it's the current time of day and second, you can't access the images directly unless you're viewing the website. For example, if I were to try and visit "http://www.bijint.com/assets/pict/cc/590x450/1742.jpg" when it was actually 17:42 I would get a 403 forbidden error UNLESS I actually had the "http://www.bijint.com/cc/" website open. I presume either it's caching the image or storing some cookie off which allows you to view the image.

Currently, I have a hacky program which has a QWebView pointed at the Circuit Tokei website and I've tried using QHttp to download the images as the website is updated every minute and I've also tried using QNetworkAccessManager to download the images too but I get a 403 forbidden error using both methods. So, I'm thinking the only way I might be able to do this is extract the images directly from either the QWebView object or perhaps the QWebPage or maybe even QWebFrame when they're updated. Thing is, I'm not sure how to do this. There doesn't seem to be any information on how to do anything like this in the docs.

Any ideas?

axeljaeger
19th January 2010, 21:45
See this example: http://labs.trolltech.com/blogs/2009/08/04/openstreetmap-and-qt-and-s60/

For the magnifier-glass, they take an image of the webpage.

redneon
20th January 2010, 10:18
This is actually a workaround I'm using at the minute. I'm rendering the web element to a QPixmap. It works fine but what I don't like is that when I save the QPixmap to my hard drive I'll effectively be incurring any compression artifacts twice. So ideally I'd like a better solution. I get the impression that there isn't one, though :)

axeljaeger
20th January 2010, 10:51
Why do you have compression artifacts at all? If you save as PNG, there shall be no compression artifacts.

redneon
21st January 2010, 08:13
Well, I'm using JPG at the minute. If PNG is lossless though then I'll use that but I don't think it is, is it?

redneon
21st January 2010, 08:35
Ok. Wikipedia informs me that PNG is lossless. In which case, will the quality argument of QPixmap::Save() be ignored if I set the format argument to PNG?

axeljaeger
21st January 2010, 09:03
I guess it will be ignored at all for image formats that do not have lossy compression.