ArchiveTeam/wpull

Website directory as folder with index.html file within

jaredxx1 opened this issue · 1 comments

Hello,

So I just trying to use the tool and found that it does not respect the website structure.

Example: https://medium.economist.com/refugee-camp-diary-31f2fe2942ef
After fetching, it creathes the following file: refugee-camp-diary-31f2fe2942ef
A nicer option would be to make the file "refugee-camp-diary-31f2fe2942ef" a directory, then create an index.html file with the contents of refugee-camp-diary-31f2fe2942ef.

I can't find any workaround, maybe it already has this feature but I can't figure it out.

Please guide me.

Thanks!

The current behaviour is expected and correct. Here's why:

Firstly, that URL is not a "directory" since it does not end with a slash. (I'm putting that in quotes since paths in URLs don't actually (need to) map to directories; it's just a similar hierarchical structure.) From wpull's perspective, that URL is for a single file.

Secondly, for single-file downloads, it's expected that this is stored in a file of the same name. For example, if you downloaded an audio file https://example.org/foo.ogg, you'd want foo.ogg, not foo.ogg/index.ogg or similar. It's impossible to reliably guess what structure you might desire, so storing it as a file with the same name is the only reasonable approach.

Thirdly, it's what wget does. Since wpull is intended to be a mostly drop-in replacement for wget, we can't really change that behaviour.


Now, here are a few ideas what you could do instead:

  1. Use --adjust-extension. This would produce refugee-camp-diary-31f2fe2942ef.html in the current directory, which might be closer to what you want.

  2. Specify the desired filename using --output-document. For example, wpull --output-document refugee-camp-diary-31f2fe2942ef/index.html https://medium.economist.com/refugee-camp-diary-31f2fe2942ef should do what you'd expect, but there seems to be a bug due to the redirects which I'll file separately (edit: filed as #453). It works with wget. Note that the directory already has to exist for this to work.

  3. For Medium specifically, you can add a slash at the end of the URL. This works because the server will redirect you back to the proper URL again. It would also work for servers which return the same content when that slash is added. But there are many cases where it won't work.
    What the extra slash does is make wpull think it's a "directory". Now, without any further options, this would just produce index.html in your current directory, but you can use --force-directories to make it create a directory structure even for this single file; then you'd get a file medium.economist.com/refugee-camp-diary-31f2fe2942ef/index.html. (If you use any sort of recursion option, e.g. --page-requisites, you can drop --force-directories.)

Hope this helps. I'll close this issue since there's nothing to do in terms of wpull development, but feel free to ask any further questions you have!