how to get images from other web page and show in

2020-03-31 04:57发布

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

Case flow is:

  1. Type some page URL in text box and submit
  2. Collect all images in that web page (not in entire site) and show them in my webpage

3条回答
Melony?
2楼-- · 2020-03-31 05:26

First of all check for Copyright. Copy only if the image is provided by the owner for free use. Also read and understand the license of usage.

If the image is free to use as stated by the owner under license then download the image and then use it. Also, please don't forget to keep copy of the license and the website url from where you downloaded the image.

Download and then use is suggested so that if tomorrow the other website shuts down then your website remains unaffected.

Last but not the least, try to design/ shoot your own images. Even if they are not as good as others at least they are genuine.

查看更多
ら.Afraid
3楼-- · 2020-03-31 05:30

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

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.

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.

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

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

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. 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.

查看更多
够拽才男人
4楼-- · 2020-03-31 05:49

If you want do scrape other websites with javascript, you should create a server side script which can act as proxy or you can use YQL.

Here's my answer for cross domain ajax call with YQL,

Cross Domain Post method ajax call using jquery with xml response

查看更多
登录 后发表回答