Group Abstract Group Abstract

Message Boards Message Boards

0
|
14.2K Views
|
7 Replies
|
5 Total Likes
View groups...
Share
Share this post:

Import Image from Website

Posted 11 years ago

Sorry begginer here. I'm trying to pull in an image from any website you choose. I'm not having the problem grabbing the image off a website using

Import["www.redditcom/r/itookapicture","Images"][[2]]

The problem I'm having is creating an API that will allow you to insert any website you would like. The code I'm trying to make work is as follows

APIFunction[{"Website" ->;<|"URL" ->"String"|>},Import[#Website,"Images"][[2]]]

It is erroring out with

?FormFunction[{Website ?;?URL ?String|>},Import[Website,Images]]" is incomplete; more input is needed

Any help would be much appreciated.

POSTED BY: Danny Pace
7 Replies
Posted 11 years ago

Ah ok. I already tried both CloudDeploy[f] and the ?Website= and I could not get it to work. I'm glad that you told me that it was broken. Again, thanks for taking your time to explain it to a newbi like me.

POSTED BY: Danny Pace

Import of website images now works from a cloud deployed APIFunction, FormPage, etc. Last week my reply to Sean Clarke’s post missed this fact, but I’ve updated it to show that his API function is now working.

POSTED BY: Sean Clarke

This still seems to be an issue, see http://mathematica.stackexchange.com/q/97751/1635 Any ideas for a workaround when you want a program to run in the cloud, gather data from a website x that is a parameter to the program?

POSTED BY: Fredrik Doberl

Import HTML images

Deploy and test Sean Clarke's API:

With[{cloudobject = FileNameJoin[{$CloudRootDirectory, "ImportHTMLImageAPI"}]},
   CloudDeploy[
      APIFunction[{"Website" -> "SemanticURL"}, First@Import[#Website, "Images"] &, "JPEG"],
      cloudobject, Permissions -> "Public"];
   URLExecute[URLBuild[cloudobject, {"Website" -> "google"}]]]

For the above query "google" the API returns:

Google homepage image

Eventually, a better solution might be to import HTML images from a private cloud.

Update 12/18/15

Previous update on 12/14/15 confirmed Sean Clarke's API was working, but the CloudObject had default "Private" permissions, which works fine from a browser signed into the Wolfram Development Platform, but gives an signin error from URLExecute.

Posted 11 years ago

First, thank you for taking the time to reply. Second, You are hardcoding the website in the code. How do you pass any website into the API?

POSTED BY: Danny Pace

The second argument to APIFunction should be a function. The most common way to give the function is as a pure/anonymous function. To make a pure/anonymous function, you are missing the apersand:

f = APIFunction[{"Website" -> <|"URL" -> "String"|>}, Import[#Website, "Images"] &]

f[<|"Website" -> "http://www.google.com"|>]
POSTED BY: Sean Clarke
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard