Super embarrassing Image link bulk acquisition and download _php tutorials

Source: Internet
Author: User
In the past under Windows often go to some wallpaper site, or the beauty of the QQ album, or is a Passion beauty pictures website Download pictures, often need to click the right button and then "Save as", if you meet the classic set of pictures, this repetitive operation will certainly let you lose the power of download. Later used Firefox has a plug-in seems to be downloadthemall (remember not clear, anyway, is the bulk download Web links, you can filter the format to download pictures), combined with the use of thunder can greatly improve the efficiency of the picture download (but if the page small picture too much, It also takes a long time to filter out deleted files. Now with Ubuntu, no windows and thunder, nor Firefox for many years. How do we download the images from the page in bulk? In Chrome I've been looking for such a plugin, but only to find the IMG Inspector plug-in, which works by defining a base URL, using placeholders, defined stride size and loop range to regenerate links and preview. Have to say that such a function is too weak, even if the URL of the set diagram is not necessarily a regular follow-up, so this method is not desirable or practical.
So later thinking about learning chrome plug-in development, to do a pity has been no motivation. And I don't know if the chrome plugin can solve the problem with the download of the image: whether it's calling the client to download the software or calling the native browser to download it, and that's a good way to learn some of the high-level methods of Chrome's API and increase the cost of development. and gave up. So the change of thinking continues to ponder. Then take a few difficult questions one by one minutes apart to analyze (environment: UBUNTU+CHROME/FIREFOX):

1) How to get the picture address of the current page?

The simplest thing to do is to execute a script in Chrome's console or Firebug, and I'd also like to take advantage of web crawler tools like Simplehtmldom, a powerful open source framework (if you're familiar with jquery This framework lets you use jquery to get tags on the server side, Very convenient), but the efficiency of this possible implementation is a poor one. Complexity has also increased a bit.

2) How do I determine if the picture size of the current page matches my "appetite"?

The problem is scored in two scenarios: Web images are generally divided into thumbnails and originals. Thumbnails are usually accompanied by a link to the original image. That is, to wrap an IMG tag with a tag, we need to get the href value of the A tag instead of the SRC value of the IMG tag; The original image is typically an IMG tag, so you can filter the images by using the width and height of the object. For thumbnail filtering, you can filter the height and width of a new image object by setting the SRC value. But for thumbnails I generally do not filter, such pictures are generally very large, on the contrary, you are most likely to filter a tag inside the IMG object, because a lot of logo and button pictures are linked to the small picture of the package.

3) How do I download pictures?

The above two steps are done using the console's script, the entire code no more than 10 lines (including the jquery Camera loaded code). Finally you can not scrap Chuihuizhili get the address of the image after the current page filter. Unfortunately in this step, get the address is not used, the real waste operation of the steps in how to download these pictures to the local machine at once. If I have chrome plugin development, I know how chrome calls the system (and I'm not sure if Chrome can, if the browser's security restrictions are strict enough), then be familiar with the powerful download command of wget. This will be solved. Unfortunately, the first two I'm not familiar with, but it's okay despair, all roads through Rome, there will be another way.

4) fly over the consoles console

Now our ideas are stuck in the chrome console, there are plenty of pictures link but do not know how to download them (in fact, just the current window of the picture link). I always have a little fantasy about chrome plug-in development, but the motivation of learning is not, and I have always questioned that Chrome is such a safe and strict browser will allow JS to interact with the client?

So I began to think backwards, not download files, directly stored in any of the local I can read in the future where the line. The idea went on to HTML5 's local storage localstorage and local database, as well as Google Gears's local database, and later found it either too complex or unworkable. Slowly the train of thought began to drift in a simple direction--jquery, yes he--$.getjson (). If you can cross-domain to send a picture address to a local site and then download in the background is not it? So immediately with code Igniter made a website: only in the controller to add a only one method of the PHP controller class file, the code is still not more than 10 lines. The function of the code is simply to write all the picture links to a text file (Urls.txt).

5) Invincible Downloader

By the end of this, perhaps someone asked me, you do not have to implement the download picture? Hey, NB characters to debut: Wget-i-B urls.txt. Enter the site directory inside the terminal, execute the command, automatically download the text file inside each line of the picture address.

PS: A few days ago this command is not familiar with an H net to do experiments, misuse of parameters in the background silently downloaded the 1.1G Huangtu, and later found a forced kill the process. In short this command download website content that is tough to not. If you use Linux, this command is evil, want to do bad things to a bit oh!

6) Can you be embarrassed?

This operation process is really embarrassing.

A) Deploy the local site-"B" right-click on the chrome console or firebug--"c) Copy Script-" D) Paste-"E" enter--f "Open terminal--g" wget. This operation is very convenient for a page with many pictures (thumbnails, sets of images). But if I open 10 pages, each page will have to do B and D and E, if the script can be made into the chrome plugin embedded in the browser can save at least 2 steps: Open the page manually click the plugin icon or set to automatically execute the script. The ease of use is greatly improved.

Second: How to save wget this step, directly in the PHP background to perform the download. This needs to consider the use of PHP calls Ubuntu system method, not ripe, pending research.

Three: How to save the site to deploy this step, the root cause of the need for the site is that I can not merge the picture address of multiple pages together, consider the cookie but the size limit is a problem, the picture address hundred very normal (especially when the Chinese language). Also consider the problem of storing the back of the read to invoke.

These questions have not been taken into consideration and are now being considered for a two. In fact, the process of technology itself is not much improvement, but later recalled the whole process, found that the opposite of the problem when the thinking and methodology above have been significantly improved. You are welcome to discuss!


Excerpt from Hurry's column

http://www.bkjia.com/PHPjc/478448.html www.bkjia.com true http://www.bkjia.com/PHPjc/478448.html techarticle in the past under Windows often go to some wallpaper site, or the beauty of the QQ album, or is a Passion beauty pictures website Download pictures, often need to click the right button and then save As, if ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.