Save loaded images from a web browser with Webkit in Python - python

today I started developing my Python app. Using GTK and Webkit for Python. And now I have a problem: I want to save a loaded image from the web browser to my computer but I can't download it as a normal image because it's a dynamic image generated by PHP.
With VB.NET I managed to do it, but I want my application to be cross-platform.
Any idea how can I do it?
I want to "clone" the image shown in the web browser, but I can't download it because it is dynamic. In vb.net you execute the command copy and then you save it.
EDIT 2: I have found the solution:
web.copy_clipboard()
clipboard = gtk.clipboard_get()
image = clipboard.wait_for_image()
image.save("test.png", "png")
First make sure that you selected the image.

Related

Python with Webbot, not sure how to click the button of the chrome PDF viewer

I have a Python app navigating through a website using Webbot. On the final page, it renders and streams a PDF to the browser (without an endpoint URL). This is displayed in the chrome PDF viewer but I need to download this.
I am unsure of how to go about activating the download here or obtaining this file through the normal method of request.get()
The URL is generic: www.website.com/generatePDF
chrome viewer showing download button
I can navigate to this page, I'm just not sure how to go about getting the actual PDF downloaded. Because everything uses scripting on the backend, I need to navigate button clicks (URL's are hidden).
Thoughts?
Have you consider sending CTRL+S command? It should send the save command and then click on SAVE button. Never tried but could do the job.

Can I manipulate an image in the browser with github pages?

Is it possible to upload and manipulate a photo in the browser with GitHub-pages? The photo doesn't need to be stored else than just for that session.
PS. I'm new to this area and I am using python to manipulate the photo.
GitHub pages allows users to create static HTML sites. This means you have no control over the server which hosts the HTML files - it is essentially a file server.
Even if you did have full control over the server (e.g. if you hosted your own website), it would not be possible to allow the client to run Python code in the browser since the browser only interprets JavaScript.
Therefore the most easy solution is to re-write your code in JavaScript.
Failing this, you could offer a download link to your Python script, and have users trust you enough to run it on their computer.

Is it possible to put an image from a URL into the terminal

I have an image hosted at a specific url online and I would like that image to appear in the terminal when run. Is that possible or is there a way the image can be shown in a native image viewer?
You'll need some way of fetching and displaying the image. A web browser can do both of those things, so one way to do what you want is to start up a web browser and point it at the desired URL:
import webbrowser
webbrowser.open(url)
If the user already has a web browser open but it is not currently visible (i.e. it's minimized or it's on a different virtual desktop), it might work better to tell webbrowser to open the page in a new window, which would (presumably) be displayed on the current screen:
webbrowser.open_new(url)
However, this is not guaranteed to work (perhaps the browser is configured to always display new urls in a tab instead of a new window, etc etc.)

google maps custom marker not displaying as my custom icon

I'm using motionless in python (3.5) to build static map images.
I was having a hard time to create custom markers. But it seems like it's not so much the framework or my code, but the google maps API itself.
I can't figure out what's wrong with my URL,while this URL, works.
I use this icon:
https://raw.githubusercontent.com/havnar/sprites/master/ico/1.ico
While the stack overflow favicon just works:
http://cdn.sstatic.net/Sites/stackoverflow/img/favicon.ico
There was an issue with your icon file. I have re-saved the file out and uploaded to my own Github and it loads fine now:
https://maps.googleapis.com/maps/api/staticmap?zoom=17&size=512x512&maptype=hybrid&markers=icon:https://raw.githubusercontent.com/zensign/ico-test/master/favicon3.ico%7C34.052230%2C-118.243680
You can grab the working .ico file here: https://raw.githubusercontent.com/zensign/ico-test/master/favicon3.ico

Is there a way to resize jpgs via http in python?

I am writing a webcrawler that finds and saves the urls of all the images on a website. I can get these without problem. I need to upload these urls, along with a thumbnail version of them, to a server via http request, which will render the image and collect feature information to use in various AI applications.
For some urls this works no problem.
http://images.asos-media.com/products/asos-waxed-parka-raincoat-with-zip-detail/7260214-1-khaki
resizes into
http://images.asos-media.com/products/asos-waxed-parka-raincoat-with-zip-detail/7260214-1-khaki?wid=200
but for actual .jpg images this method doesn't work, like for this one:
https://cdn-images.farfetch-contents.com/11/85/29/57/11852957_8811276_480.jpg
How can I resize the jpgs via url?
Resizing the image via the URL only works if the site you're hitting is using a dynamic media service or tool in their stack. That's why ASOS will allow you to append a query with the dimensions for resize, however different DM tools will have different query parameters.
If you want to make it tolerant you're best off downloading the image, resizing it with Python and then uploading it.

Categories