Rails 如何实现 Google 相册图片借链?

Drolmok · 2012年03月18日 · 最后由 Drolmok 回复于 2012年03月18日 · 2885 次阅读

在 android 开发了一款产品使用 rails 做对应产品手机网站的 产品升级的时候用户下载图片过多导致流量达到 5m 峰值,反应很慢 所以想借用https://play.google.com/store 上产品本身使用到的图片,想着也是推广 android 本身的产品,行为是 - 盗--- 链,目的不是盗----链,也在推介 android 的产品,呵呵

google 不是不给你用外链,是访问次数超过之后就会出 403 测试了之后 google 也是通过对 refer 的识别来做访问次数限制,如果用 Mechanize.new 去抓取是没问题的,因为这个时候 refer 是空的

google 了一下可以用 ifame 方法来做,单个页面测试了也是 ok 但是放在动态页面和 Jquery 的 infinitescroll 插件一起使用的话就出问题了。

有没有其他方法可以做到在 web 页面里面使用跨域图片但是 refer 是空的呢? ==== 部分代码

var $container = $('#container'); $container.imagesLoaded(function(){ $container.masonry({ itemSelector: '.box', columnWidth: 100 }); }); $container.infinitescroll({ navSelector : '#page-nav', // selector for the paged navigation nextSelector : '#page-nav a', // selector for the NEXT link (to page 2) itemSelector : '.box', // selector for all items you'll retrieve loading: { finishedMsg: 'No more themes to load.', img: 'http://i.imgur.com/6RMhx.gif' } }, // trigger Masonry as a callback function( newElements ) { freshImage(); // hide new items while they are loading var $newElems = $( newElements ).css({ opacity: 0 }); // ensure that images load before adding to masonry layout $newElems.imagesLoaded(function(){ // show elems now they're ready $newElems.animate({ opacity: 1 }); $container.masonry( 'appended', $newElems, true ); }); } );

Js 动态 build iframe

function showImg( tid ) { document.write('<iframe id="'+tid+'" src="javascript:parent.src['+tid+'];" onload="javascript:this.width=75;this.height=125;" frameBorder="0" scrolling="no" width="100%"></iframe>'); }

Js build iframe 的来源内容

window.src=[]; <%=xxx.each do |t| %> window.src[<%=t.id%>] = "<a href='javascript:void(0)' onclick='window.parent.gotoUrl(<%=t.id%>)' ><img src='<%=t.img_url%>=h116'></a>"; <%end%>

Js build 调用对象

<%=xxx.each do |t| %> showImg( tid ) <%end%>
需要 登录 后方可回复, 如果你还没有账号请 注册新账号