使用 Perl 或任何其他语言批量下载文件

发布于 2024-10-08 21:47:00 字数 340 浏览 0 评论 0原文

我对 JS、HTML、CSS、C、C++ 和 C# 有很好的了解。我有一个为我们学生提供试卷的网站,但是要下载这些试卷,我们必须访问每个页面,这对我们来说太难了。大约有150个文件。所以...;)

下载链接总是这样的:

http://www.example.com/content/download_content.php?content_id=#

其中#是一个数字。

所以我想如果javascript或perl或python或任何其他语言可以下载文件并自动保存在本地。目前我不需要太多,只需要基本代码。我会学习这门语言,然后我会自己发展它。所以请各位朋友帮帮我..

I have pretty good knowledge in JS, HTML, CSS, C, C++ and C#. I have this website which offers question papers for us school students, but to download those we have to visit every page and it's too hard for us. There are about 150 files. So... ;)

The download links always look like this:

http://www.example.com/content/download_content.php?content_id=#

where # is a number.

So I thought if javascript or perl or python or any other language can download the files and save it locally automatically. Currently I don't need much, just the basic code. I'll learn the language and then I'll develop on it myself. So please help me out pals..

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

夜声 2024-10-15 21:47:00

这就是我通常在 bash 中执行此类操作的方式:

for i in `seq 1 1000` ; do wget "http://www.example.com/content/download_content.php?content_id=$i" -O $i.html ; done

UPDATE 由于 URL 指向多个文件类型,因此您可以使用 file 命令来识别下载文件的类型,并相应地调整扩展名:

for i in `seq 1 1000`
do
   wget "http://www.example.com/content/download_content.php?content_id=$i" -O $i.out
   mime=`file --brief --mime-type $i.out`
   if [ "$mime" == "application/pdf" ]
   then
      mv $i.out $i.pdf
   elif [ "$mime" == "application/vnd.ms-office" ]
   then
      mv $i.out $i.doc
   fi
done

That's how I usually do such things in bash:

for i in `seq 1 1000` ; do wget "http://www.example.com/content/download_content.php?content_id=$i" -O $i.html ; done

UPDATE Since the URLs point to more than one file type, you could use the file command to identify the type of a downloaded file, and adjust the extension accordingly:

for i in `seq 1 1000`
do
   wget "http://www.example.com/content/download_content.php?content_id=$i" -O $i.out
   mime=`file --brief --mime-type $i.out`
   if [ "$mime" == "application/pdf" ]
   then
      mv $i.out $i.pdf
   elif [ "$mime" == "application/vnd.ms-office" ]
   then
      mv $i.out $i.doc
   fi
done
淡忘如思 2024-10-15 21:47:00

这将使用 wget 程序在 shell 脚本中完成此操作,将它们全部转储到当前目录中:

#!/bin/sh
i=1
while [ $i -le 150 ]; do
  wget -O $i.out "http://www.example.com/content/download_content.php?content_id=$i"
  i = $((i + 1))
done

This will do it in shell script using the wget program, dumping them all into the current directory:

#!/bin/sh
i=1
while [ $i -le 150 ]; do
  wget -O $i.out "http://www.example.com/content/download_content.php?content_id=$i"
  i = $((i + 1))
done
新人笑 2024-10-15 21:47:00

如何使用curl代替:

curl -O http://www.example.com/content/download_content.php?content_id=#[1-150]

应该适用于大多数Linux发行版,如果没有,您可以从这里下载curl:http:// curl.haxx.se/ 或使用“apt-get install curl

How about using curl instead:

curl -O http://www.example.com/content/download_content.php?content_id=#[1-150]

Should work on most linux distros and if its not there you can download curl from here: http://curl.haxx.se/ or with a 'apt-get install curl'

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文