如何从其他网页获取图像并在我的网站上显示 [英] how to get images from other web page and show in my website

查看:93
本文介绍了如何从其他网页获取图像并在我的网站上显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是想知道如何从其他网页获取图片并在我的网站上显示。

I just want to know how to get images from other web page and show in my website.

案例流程为:


  1. 在文本框中键入一些页面URL并提交

  2. 收集该网页中的所有图像(不是整个网站)并在我的网页上显示它们


推荐答案

所以,你需要从页面获取图像,输入数据是该页面的地址。那么,你有两个解决方案:

So, you need to get images from page, and the input data is thh address of that page. Well, you have two solutions:

我。如果这是您的网站的功能,其他人将使用,那么普通的JavaScript是不够的,因为浏览器的隐私政策阻止从其他页面获取此类数据。在这种情况下,您需要将URL发送到服务器上的脚本,该脚本将下载该页面,将其解析为s并返回图像srcs列表。

I. If this is functionality for your site which others will use, then plain JavaScript is not enough, because browser's privacy policies block getting such data from other pages. What you need in this case is to send the URL to a script on your server, which will download that page, parse it for s and return you the list of image srcs.

如何做到这一点是一个非常复杂的问题,因为它取决于你网站的serever端编程语言。无论如何,这样的功能将包括使用AJAX技术的客户端javascript和服务器站点脚本(例如php)。客户端脚本非常简单。

How exactly to do this is a pretty complicated question, for it depends on your site's serever-side programming language. Anyway such functionality would consist of client side javascript using AJAX techniques and server site script (e.g. php). Client script which is pretty much straight-forward.

在客户端,您的js必须:

On client side your js has to:

1. Get desired URLs
2. Send them to server
3. Wait for server's response (which contains srcs of images on desired page)
4. Create img tags with srcs which you got from server script

谷歌的关键词例如是AJAX,XmlHttpRequest和JSONP(对不起,如果你已经知道了)那个:)

Keywords for this to google are, for example, AJAX, XmlHttpRequest and JSONP (sorry if you already know that :)

在服务器端你的(php | ruby​​ | python | perl | brainfuck)必须:

On server side your (php|ruby|python|perl|brainfuck) has to:

1. Get page URL from javascript code at step 2
2. Download a page by that url
3. Parse it looking for img tags and their srcs
4. Send list of srcs (in XML, JSONP or any other form) back to client

II。如果您需要从其他页面获取图像仅供个人使用,您可以为浏览器编写扩展程序。这种方式不需要任何服务器端脚本。

II. If you need to get images from other pages only for your personal use, you can write an extension for your browser. This way doesn't require any server side scripts.

这篇关于如何从其他网页获取图像并在我的网站上显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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