【问题标题】:WGET: want all files/pdfs from a site, dir gets created, but no files are downloadedWGET:想要来自站点的所有文件/pdf,创建目录,但没有下载文件
【发布时间】:2018-10-25 22:48:15
【问题描述】:

我显然太健忘(w)获取所有幻灯片。

拥有一个 pdf 和 ppt 填充的网站:http://some.uni.edu/~name/slides.html 我想一次性下载所有(许多)链接文件。 到目前为止,该目录是由 wget 创建的,但它是空的。

我试过了:

wget -r -A.pdf,.ppt http://some.uni.edu/~name/slides.html
wget -e robots=off -A.pdf,.ppt -r -l1 http://some.uni.edu/~name/slides.html
wget -nd -l -r -e robots=off http://some.uni.edu/~name/slides.html 
wget -r -np -R "slides.html" http://some.uni.edu/~name/slides.html  
wget -r -np -R "slides.html" http://some.uni.edu/~name/

例如:

$ wget -r https://web.cs.ucla.edu/~kaoru/
--2018-10-29 21:38:50--  https://web.cs.ucla.edu/~kaoru/
Resolving web.cs.ucla.edu (web.cs.ucla.edu)... 131.179.128.29
Connecting to web.cs.ucla.edu     (web.cs.ucla.edu)|131.179.128.29|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 623 [text/html]
Saving to: ‘web.cs.ucla.edu/~kaoru/index.html’

web.cs.ucla.edu/~ka 100%[===================>]     623  --.-KB/s    in 0s      

2018-10-29 21:38:51 (19.1 MB/s) -     ‘web.cs.ucla.edu/~kaoru/index.html’ saved [623/623]

Loading robots.txt; please ignore errors.
--2018-10-29 21:38:51--  https://web.cs.ucla.edu/robots.txt
Reusing existing connection to web.cs.ucla.edu:443.
HTTP request sent, awaiting response... 200 OK
Length: 95 [text/plain]
Saving to: ‘web.cs.ucla.edu/robots.txt’

web.cs.ucla.edu/rob 100%[===================>]      95  --.-KB/s        in 0s      

2018-10-29 21:38:51 (3.10 MB/s) - ‘web.cs.ucla.edu/robots.txt’ saved [95/95]

--2018-10-29 21:38:51--  https://web.cs.ucla.edu/~kaoru/paper11.gif
Reusing existing connection to web.cs.ucla.edu:443.
HTTP request sent, awaiting response... 200 OK
Length: 10230 (10.0K) [image/gif]
Saving to: ‘web.cs.ucla.edu/~kaoru/paper11.gif’

web.cs.ucla.edu/~ka 100%[===================>]   9.99K  --.-KB/s    in 0.001s  

2018-10-29 21:38:51 (12.3 MB/s) -     ‘web.cs.ucla.edu/~kaoru/paper11.gif’ saved [10230/10230]

FINISHED --2018-10-29 21:38:51--
Total wall clock time: 0.9s
Downloaded: 3 files, 11K in 0.001s (12.2 MB/s)

仍然不下载文件:

$ ls 
$ index.html  paper11.gif

【问题讨论】:

  • 你试过--ignore-case吗?否则-A.pdf.PDF 不匹配。
  • 谢谢!刚试了一下,没有成功..
  • 目标 PDF 是否在同一台服务器上?尝试-H 以允许 wget 访问其他主机。显然,如果不访问相关页面,就很难回答。
  • 我明白,是的,所有文件都位于“some.uni.edu/~name”,例如“some.uni.edu/~name/slides001.pdf”、“some.uni.edu/~name/slides002.ppt”等。
  • 好的,那应该工作。这不太可能,但服务器可能会基于用户代理(等)被阻止。你能wget 那些直接文件 URL 之一吗?例如:wget https://some.uni.edu/~name/slides002.ppt

标签: download wget


【解决方案1】:

你的例子

wget -r -A.pdf,.ppt http://some.uni.edu/~name/slides.html
wget -e robots=off -A.pdf,.ppt -r -l1 http://some.uni.edu/~name/slides.html
wget -nd -l -r -e robots=off http://some.uni.edu/~name/slides.html 
wget -r -np -R "slides.html" http://some.uni.edu/~name/slides.html

不应该按照您想要的方式工作,因为您专门针对单个 html 文件,即 slides.html。您应该以目录为目标。

但是,你的最后一个例子是我认为最接近的。

由于@Kingsley 的示例适合您,您应该先尝试此方法,然后再开始使用-R-A 文件。

wget -r http://some.uni.edu/~name/

也许应该是https!?

无论如何,如果不允许“目录列表”(由服务器控制),那么wget 无法递归获取所有文件。它只能获取您知道名称的特定文件!

【讨论】:

  • 谢谢!实际上,该示例部分工作 - 我可以从直接 URL 获取一个文件。我仍然必须手动获取所有 PDF 的..
  • @marc111011 从示例中下载了哪个文件?
  • 当我使用wget https://some.uni.edu/~name/slides002.ppt 时,我确实得到了slides002.ppt。但是我必须这样做 50 次,并且点击比更改名称要快:)
  • @marc111011 然后我有两个问题。 1.你用http还是https? 2.使用wget -r https://some.uni.edu/~name/会得到什么
  • @marc111011 你还没有显示wget -r https://some.uni.edu/~name/ 的输出。相反,在您的示例中,您再次针对特定文件,即ppt.html。您应该定位一个目录。即您在 url 中的最后输入应该以 / 结尾,而不是特定的文件名
【解决方案2】:
wget -h |grep np,

-np, --no-parent 不升到父目录

wget -h |grep A,

-A, --accept=LIST 逗号分隔的已接受扩展列表

wget -h |grep r,

-r, --recursive 指定递归下载

尝试使用

wget -r -np -A pdf,doc https://web.cs.ucla.edu/~harryxu/

结果

tree

└── web.cs.ucla.edu
    ├── ~harryxu
    │   ├── papers
    │   │   ├── chianina-pldi21.pdf
    │   │   ├── dorylus-osdi21.pdf
    │   │   ├── genc-pldi20.pdf
    │   │   ├── jaaru-asplos21.pdf
    │   │   ├── jportal-pldi21.pdf
    │   │   ├── li-sigcomm20.pdf
    │   │   ├── trimananda-fse20.pdf
    │   │   ├── vigilia-sec18.pdf
    │   │   ├── vora-asplos17.pdf
    │   │   ├── wang-asplos17.pdf
    │   │   ├── wang-osdi18.pdf
    │   │   ├── wang-osdi20.pdf
    │   │   ├── wang-pldi19.pdf
    │   │   └── zuo-eurosys19.pdf

【讨论】:

  • 这看起来是一个简洁而有用的问题答案!您可以通过详细说明您使用的 CLI 参数以及为什么这样做以及为什么问题中描述的步骤不起作用来改进它。
猜你喜欢
  • 2013-11-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-02-04
  • 1970-01-01
  • 1970-01-01
  • 2016-02-22
  • 1970-01-01
相关资源
最近更新 更多