拍摄并显示图像 [英] Take and display images

查看:223
本文介绍了拍摄并显示图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我需要从外部链接网站获取所有图片,并将其显示在其他网站中。是否可以做没有jQuery?用简单的javascript或flash?

任何人都可以推荐一些教程的东西或者什么?

如果javascript,那么它必须是非常简单的代码,因为我想使它在eBay上市的工作。



例如:在上市将出售持有人XXX手机,我想把幻灯片或类似的东西放在底部(同一类别)。我想给它一个funcionality,所以我只需要改变链接到类别和图片会自动改变。更多钞票?



谢谢,

请如果我没有弄清楚,请问我会详细解释。

解决方案

注意:提问者声明这个答案不起作用。
除此之外,它工作得很好,它会刺激一些网络开发者(LOL)。我现在就把它留在这里。

我有一个鬼鬼祟祟的怀疑,你没有拥有/控制外部链接网站,因此从外部链接网站的所有图像,并显示在其他网站(如问),将下降根据跨域安全的限制。

因此为了重新获得用户的权力,只需使用 http://query.yahooapis.com/
jQuery不会被严格需要。

  > select * from html 
where url =http://stackoverflow.com
和xpath ='// div / h3 / a'
pre>

以下链接w虐待SO最新的问题(绕过跨域安全公牛$#!7):

http://query.yahooapis.com/v1/public/yql?q=select%20%2a%20from%20html%20%0Awhere%20url% 3D%22http%3A%2F%2Fstackoverflow.com%22%20%0Aand%20xpath%3D%27%2F%2Fdiv%2Fh3%2FA%27%3B&安培;格式= JSON&安培;回调= cbfunc



正如你所看到的,这将返回一个JSON数组(也可以选择xml)并调用回调函数: cbfunc

在你的情况下,你会钓鱼的图像链接,并将其包括在您的网页。

示例2:

如下面的评论所述,纯粹的示例 JavaScript不仅从Ebay商店获取图像网址,还获取产品标题的产品网址(显示为超链接)产品标题为图像标题的图像)。同样,它还显示了如何动态地构建yql字符串,以及可以如何处理返回的数据。

 函数cbfunc(json){
if(json.query.count){
var data = json.query.results.div;
var i = 0,l = data.length,htm ='';
为(; i htm + ='< a href ='+ data [i] .a.href +'>'+
' img title ='+ data [i] .a.img.title +''+
'src ='+ data [i] .a.img.src +'>'+
'< / A> \\\
';
}
document.getElementById('output')。innerHTML = htm;
} else {
alert('Error:Nothing found');返回false;


$ b $ function fetchEbayStore(url){
var yql =select a.href,a.img.src,a.img.title+
from html+
where url ='+ url +'+
and xpath ='// td / div [@ class = \image\ ]';
yql =http://query.yahooapis.com/v1/public/yql?q=+
encodeURIComponent(yql)+
& format = json+
& callback = cbfunc;
getJSON(yql); //你需要提供getJSON或者使用一个库

code
$ b

请参阅这个'quick'n dirty'jsfiddle 来看看上面的例子。记住这只是为了解释,而不是生产!

更多信息:阅读雅虎的 yql -documentation,请参阅构造函数中右侧的实例。


I was wondering how can I make this happen.

I need to take all the images from the external link site and display them in other site. Is is posible to do without jQuery? With a simple javascript or flash?

Anyone can suggest somekind of tutorial's or something?

If javascript, then it has to be very simple code, because I want to make it work in eBay listing's.

Example: In the listing there will be sold a holder for XXX cell phone, and I want to put on the bottom a filmstrip or something similar for the exact same item(from the same category). I want to give it a funcionality so I would need to change only the link to the category and the pictures would be changed automatically. POSIBLE?

Thanks,

Please If I didn't make myself clear, ask and I will explain in more detail's.

解决方案

NOTE: The askers has stated this answer does not work INSIDE Ebay listings.
Other than that, it works so well, it'll irritate some 'web-developers' (LOL). I'm leaving it here for now.

I had a sneaky suspicion you did not own/control the external link site, thus to 'take all the images from the external link site and display them in other site' (as asked), would fall under cross-domain security restrictions.

So to in order to regain 'power to the user', just use http://query.yahooapis.com/.
jQuery would not be strictly needed.

EXAMPLE 1:
Using the SQL-like command:

select * from html 
where url="http://stackoverflow.com" 
and xpath='//div/h3/a'

The following link will scrape SO for the newest questions (bypassing cross-domain security bull$#!7):
http://query.yahooapis.com/v1/public/yql?q=select%20%2a%20from%20html%20%0Awhere%20url%3D%22http%3A%2F%2Fstackoverflow.com%22%20%0Aand%20xpath%3D%27%2F%2Fdiv%2Fh3%2Fa%27%3B&format=json&callback=cbfunc

As you can see this will return a JSON array (one can also choose xml) and calling the callback-function: cbfunc.

In your case you would fish for image-links and include them in your page.

Example 2:
As asked in the comments below, this example in pure JavaScript does not only fetch image-url's from a Ebay-store, it also fetches the product-title's and product url's (displaying them as hyperlinked images with product-title as the image's title). As such it also shows how one could dynamically build the yql-string and what one could do with the data that returns.

function cbfunc(json){
   if(json.query.count){
      var data=json.query.results.div;
      var i=0, l=data.length, htm='';
      for(;i<l;i++){
         htm+='<a href="'+data[i].a.href+'">' +
                 '<img title="'+data[i].a.img.title+'"' +
                       ' src="'+data[i].a.img.src+'">' +
              '</a>\n';
      }
      document.getElementById('output').innerHTML=htm;
   } else {
      alert('Error: nothing found'); return false;
   }
}

function fetchEbayStore(url){
   var yql="select a.href, a.img.src, a.img.title" +
           " from html" +
           " where url='" + url + "'" +
           " and xpath='//td/div[@class=\"image\"]'";
   yql="http://query.yahooapis.com/v1/public/yql?q=" +
       encodeURIComponent(yql) +
       "&format=json" +
       "&callback=cbfunc";
   getJSON(yql); //you need to provide getJSON or use a library
}

See this 'quick 'n dirty' jsfiddle to see the above example in action. Remember this is just meant for explanation, not production!

For more info: Read the yahoo's yql-documentation, see the live examples on the right side in the constructor.

这篇关于拍摄并显示图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆