read image from url python code example

Example 1: python get html from url

import requests

url = requests.get("http://google.com")
htmltext = url.text

Example 2: python download image from url

import urllib.request
imgURL = "http://site.meishij.net/r/58/25/3568808/a3568808_142682562777944.jpg"

urllib.request.urlretrieve(imgURL, "D:/abc/image/local-filename.jpg")

Example 3: js get image from url

var elements = [];
function loaded(){
  console.log("you have loaded an image");
}
CreateFileFrom("your/dir/here/img.png");

function CreateFileFrom(dir){

  		/* defining runtime variables */
	  		var extension                        =   dir.split('.').pop();
	  		var keys                             =   {"png":"IMG","jpg":"IMG","jpeg":"IMG",
	  												  "js":"SCRIPT","json":"SCRIPT",
	  												  "mp3":"AUDIO","wav":"AUDIO"};
	  	    var obj                              =   document.createElement(keys[extension]) || {};
	  	    obj.src                              =   dir;
	  	    
	  	/* onload function called when the resource is loaded */
	  	    obj.onload                           =   (e) => {

	  	    	elements.push(e.path[0]);
	  	    	loaded()
	  		}

  		/* make sure that the data is compitable */
  			if(keys[extension]==null){console.error("not supported media type "+extension);return;}
  	}

Tags:

Php Example