怎么获取这个网站的图片的地址?

申祷无 2015-01-27 04:34:26
这是个例子:
http://www.vaikan.com/guangdong-programmer-at-california/
这个网站上的图片直接另存为根本无法保存图片,只是一个1*1像素的图片。
使用这种技术网站上的图片对搜索引擎的蜘蛛是不可见的吧?这个网站完全放弃SEO了?还是说现在的网络蜘蛛很厉害,可以抓取这种图片?
还有这种加载图片的技术叫什么?

我最终的目的不是保存图片,而是运行下面的代码:
大部分情况下这段代码必须在Chrome中启用--disable-web-security的情况下才能正常执行。其他浏览器不知道。可能图片的地址和网页的地址属于同一个域名就不用启用这个选项。可以参考这贴:
http://stackoverflow.com/questions/3102819/disable-same-origin-policy-in-chrome#
启用这个选项是有安全风险的,请在了解风险的情况下启用这个选项。启用的使用Chrome会有提示。
var new_canvas = document.createElement( "canvas" );
new_canvas.setAttribute( "id", "img_resizer" );
var thisbody = document.getElementsByTagName( "body" )[ 0 ];
thisbody.appendChild( new_canvas );

var canvas = document.getElementById( "img_resizer" );
var ctx = canvas.getContext( "2d" );
var imgs = document.getElementsByTagName( "img" );

for( var i = 0; i < imgs.length; i++ ) {
var MAX_WIDTH = 500;
var MAX_HEIGHT = 500;
var width = imgs[ i ].width;
var height = imgs[ i ].height;

if( width > height ) {
if( width > MAX_WIDTH ) {
height *= MAX_WIDTH / width;
width = MAX_WIDTH;
}
} else {
if( height > MAX_HEIGHT ) {
width *= MAX_HEIGHT / height;
height = MAX_HEIGHT;
}
}
canvas.width = width;
canvas.height = height;

ctx.drawImage( imgs[ i ], 0, 0, width, height );

var dataURL = canvas.toDataURL( "image/jpeg", 0.1 );
imgs[ i ].setAttribute( "src", dataURL );
}

对我为什么要运行这段代码感到好奇的话可以看一下我提的这个问题:
http://bbs.csdn.net/topics/390933892
...全文
142 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
xiao_w_xiao 2015-01-27
  • 打赏
  • 举报
回复

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Demo JavaScript PNG Viewer</title>
 </head>
<body onload="show(gravatar);">
<script src="../Source/Base64.js" type="text/javascript"></script>
<script src="../Source/Deflate.js" type="text/javascript"></script>
<script src="../Source/PNG.js" type="text/javascript"></script>

<script type="text/javascript">
var gravatar = 'iVBORw0KGgoAAAANSUhEUgAAA.......数据从略......55CYII=';
String.prototype.padRight = function(c, n){
	var txt = '';
	for(var i=0;i<n-this.length;i++) txt += c;
	return txt + this;
};
function show(data){
	var png = new PNG(data);
	var img = document.getElementById('image'), limg = document.getElementById('largeimage');
	document.getElementById('nativeimage').src = 'data:image/png;base64,' + data;
	img.innerHTML = '';
	limg.innerHTML = '';
	img.style.width = png.width + 'px';
	img.style.height = png.height + 'px';
	limg.style.width = (png.width * 3) + 'px';
	limg.style.width = (png.height * 3) + 'px';
	var line;
	while(line = png.readLine())
	{
		for (var x = 0; x < line.length; x++){
			var px = document.createElement('div'), px2 = document.createElement('div');
			px.className = px2.className = 'pixel';
			px.style.backgroundColor = px2.style.backgroundColor = '#' + line[x].toString(16).padRight('0', 6);
			img.appendChild(px);
			limg.appendChild(px2);
		}
	}
}
</script>
<div id="image"></div>
<div id="largeimage"></div>
<img id="nativeimage" />
</body>
</html>

xiao_w_xiao 2015-01-27
  • 打赏
  • 举报
回复
对应的View

<html>
<head>
<title>Hello,World</title>
</head>
<body>
<img src="data:image/png;base64,${encodeString}" />
</body>
</html>
xiao_w_xiao 2015-01-27
  • 打赏
  • 举报
回复
一个图片就是一个文件,它在互联网上传递的过程是通过数据流来传播,如果我们直接把数据流字节赋给一个图片的话,也是可以的,就是你给的网站那样,比如数据库中如果直接保存图片或者文件的话,也是一样的。 所以只要将图片压缩成存储的字符串就可以了。。。

public class Base64ImageAction extends ActionSupport {

	private final static String galleryName = "gallery";
	private static String parent = null;
         private String encodeString = null;

	public String getEncodeString() {
		return encodeString;
	}

	public void setEncodeString(String encodeString) {
		this.encodeString = encodeString;
	}


	private String getImageFullPath() {
		parent = new File(this.getClass().getClassLoader().getResource(
					File.separator).getPath()).getParent()+File.separator+"flag.jpg";
	}

	public String execute() {
		ByteArrayOutputStream output = new ByteArrayOutputStream();
		try {
			JimiReader reader = Jimi.createJimiReader(this.getImageFullPath());
			Image image = reader.getImage();
			Jimi.putImage("image/png", image, output);
			output.flush();
			output.close();
			this.encodeString = Base64.encodeBase64String(output.toByteArray());
		} catch (IOException e) {
			e.printStackTrace();
		} catch (JimiException e) {
			e.printStackTrace();
		}
	
		return SUCCESS;
	}
}

87,923

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧