Unix 如何在网站上使用尾随斜杠,并像无尾随斜杠一样保存
我用Wget创建了一个供个人使用的爬虫程序Unix 如何在网站上使用尾随斜杠,并像无尾随斜杠一样保存,unix,wget,Unix,Wget,我用Wget创建了一个供个人使用的爬虫程序 wget -k -m -Dwww.website.com -r -q -R gif,png,jpg,jpeg,GIF,PNG,JPG,JPEG,js,rss,xml,feed,.tar.gz,.zip,rar,.rar,.php,.txt -t 1 http://www.website.com/ & 网站中的帖子示例URL为http://www.website.com/post-one/,每个帖子的URL末尾都有尾随斜杠 保存后,Wget将创
wget -k -m -Dwww.website.com -r -q -R gif,png,jpg,jpeg,GIF,PNG,JPG,JPEG,js,rss,xml,feed,.tar.gz,.zip,rar,.rar,.php,.txt -t 1 http://www.website.com/ &
网站中的帖子示例URL为http://www.website.com/post-one/
,每个帖子的URL末尾都有尾随斜杠
保存后,Wget将创建:
www.website.net/post-one
www.website.net/post-one/index.html
第一行是文件夹,第二行是我要查找的实际HTML文件。问题是,Wget将为每个帖子创建一个文件夹,这使得处理数据更加困难
我想让Wget创建www.website.net/post one
哪个post one
这是HTML文件,而不是为每个帖子创建文件夹
我试过很多方法,但都不走运。使用无内容的
-R.html
结果文件夹。我使用的wget支持以下目录选项:
-nd, --no-directories don't create directories.
-x, --force-directories force creation of directories.
-nH, --no-host-directories don't create host directories.
--protocol-directories use protocol name in directories.
-P, --directory-prefix=PREFIX save files to PREFIX/...
--cut-dirs=NUMBER ignore NUMBER remote directory component
也许-nd或-p可以帮助你
否则,在使用现有wget下载所有文件后,shell脚本可以轻松地将文件转换为单级dir
#!/bin/bash
cd www.website.net
for d in $( find . -type -d -print ) ; do
if [[ -f $d/index.html ]] ; then
echo mv $d/index.html $.html && echo rmdir $d
fi
done
当您确定循环正在生成适合您的输出时,请删除回声
我希望这有帮助
另外,由于您似乎是新用户,如果您得到的答案有助于您,请记住将其标记为已接受,并/或将其作为有用的答案给予+(或-)。我使用的工作组支持以下目录选项:
-nd, --no-directories don't create directories.
-x, --force-directories force creation of directories.
-nH, --no-host-directories don't create host directories.
--protocol-directories use protocol name in directories.
-P, --directory-prefix=PREFIX save files to PREFIX/...
--cut-dirs=NUMBER ignore NUMBER remote directory component
也许-nd或-p可以帮助你
否则,在使用现有wget下载所有文件后,shell脚本可以轻松地将文件转换为单级dir
#!/bin/bash
cd www.website.net
for d in $( find . -type -d -print ) ; do
if [[ -f $d/index.html ]] ; then
echo mv $d/index.html $.html && echo rmdir $d
fi
done
当您确定循环正在生成适合您的输出时,请删除回声
我希望这有帮助
另外,由于您似乎是新用户,如果您得到的答案有助于您,请记住将其标记为已接受,和/或将其作为有用的答案给予+(或-)