A shell script _linux shell that downloads a picture of a Web page

Source: Internet
Author: User
Tags curl egrep

I remember last year when I was looking for a job interview, I heard a classmate say that he likes Linux very much, I believe what he said is true, I think the people who like Linux are very happy from the shell script, because it can integrate the various resources on Linux to do great things. Here's a picture crawler that you can share with the next shell script.
How to use:
Copy the following code, named Img_downloader.sh. When used, enter under the shell./img_downloader.sh www.baidu.com-d Images, the shell script will put the picture down on the homepage of Baidu.

Copy Code code as follows:
#!/bin/bash
If [$#-ne 3];
Then
echo "Usage: $ url-d DIRECTORY"
Exit-1
Fi

For i in {1..4}
Todo
Case is in
-d) shift; directory=$1; shift;;
*) Url=${url:-$1};shift;
Esac
Done

Mkdir-p $directory
baseurl=$ (echo $url | egrep-o "https?:/ /[a-z.] +")

echo "$baseurl"

Curl-s $url | Egrep-o "]*>" |
Sed ' s//tmp/$$.list

Sed-i "s|^/| $baseurl/|"/tmp/$$.list
CD $directory;

While read filename
Todo
Curl-s-O "$filename"--silent
Done </tmp/$$.list

Related Article

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.