Parallel download using Curl command line utility

后端 未结 8 683
抹茶落季
抹茶落季 2020-12-13 19:08

I want to download some pages from a website and I did it successfully using curl but I was wondering if somehow curl downloads multiple pages at a

8条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-13 19:33

    Well, curl is just a simple UNIX process. You can have as many of these curl processes running in parallel and sending their outputs to different files.

    curl can use the filename part of the URL to generate the local file. Just use the -O option (man curl for details).

    You could use something like the following

    urls="http://example.com/?page1.html http://example.com?page2.html" # add more URLs here
    
    for url in $urls; do
       # run the curl job in the background so we can start another job
       # and disable the progress bar (-s)
       echo "fetching $url"
       curl $url -O -s &
    done
    wait #wait for all background jobs to terminate
    

提交回复
热议问题