我试图脚本wget命令来下载一个网页,它的所有内部附件和JPEG等无法通过wget的一个变量引用变量
当我进入手动脚本,它的工作原理,但我需要运行这35000多次来存档一个不受我控制的旧网站(国际公司政治,但我是数据的所有者)。
我的问题一直在变化会话参数。
我的剧本至今如下:
cnt=35209
# initialise the headers
general_settings='-4 -P xyz --restrict-file-names=windows -nc --limit-rate=250k'
html_page_specific='--convert-links --html-extension'
proxy='--proxy-user=xxxxxx --proxy-password=yyyyyyy'
session="--header=\'Host: mywebsite.com:9090\' --header=\'User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:20.0) Gecko/20100101 Firefox/20.0\'"
address=http://mywebsite.com:9090/browse/item-$cnt
echo $general_settings $proxy $session $cookie $address
echo
echo
echo Getting item-$cnt...
#while [ $cnt -gt 0 ]
#do
# # get the page
wget --debug $general_settings $html_page_specific $proxy $session $cookie $address
# now get the attachments, pdf, txt, jpg, gif, sql, etc...
# wget -A.pdf $general_settings -r $proxy $session $cookie $address
# wget -A.txt $general_settings -r $proxy $session $cookie $address
# wget -A.jpg $general_settings -r $proxy $session $cookie $address
# wget -A.gif $general_settings -r $proxy $session $cookie $address
# wget -A.sql $general_settings -r $proxy $session $cookie $address
# wget -A.doc $general_settings -r $proxy $session $cookie $address
# wget -A.docx $general_settings -r $proxy $session $cookie $address
# wget -A.xls $general_settings -r $proxy $session $cookie $address
# wget -A.xlsm $general_settings -r $proxy $session $cookie $address
# wget -A.xlsx $general_settings -r $proxy $session $cookie $address
# wget -A.xml $general_settings -r $proxy $session $cookie $address
# wget -A.ppt $general_settings -r $proxy $session $cookie $address
# wget -A.pptx $general_settings -r $proxy $session $cookie $address
# wget -A.png $general_settings -r $proxy $session $cookie $address
# wget -A.ps $general_settings -r $proxy $session $cookie $address
# wget -A.mdb $general_settings -r $proxy $session $cookie $address
# ((cnt=cnt-1))
#
#done
但是当我运行该脚本,我得到下面的输出
Getting item-35209...
Setting --inet4-only (inet4only) to 1
Setting --directory-prefix (dirprefix) to xyz
Setting --restrict-file-names (restrictfilenames) to windows
Setting --no (noclobber) to 1
Setting --limit-rate (limitrate) to 250k
Setting --convert-links (convertlinks) to 1
Setting --html-extension (htmlextension) to 1
Setting --proxy-user (proxyuser) to xxxxx
Setting --proxy-password (proxypassword) to yyyyy
Setting --header (header) to \'Host:
Setting --header (header) to 'Cookie:
DEBUG output created by Wget 1.11.4 Red Hat modified on linux-gnu.
正如你所看到的,主机和Cookie的部分是不格式正确,导致wget命令无法登录并提取数据。
我一直在阅读bash手册页,使用谷歌搜索,并尝试了几个相关的建议,但我仍然无法获得执行命令。
任何人都会有足够的精神向我展示正确的方式来引用可读性中的引号吗?
感谢,带引号的字符串或变量的内部
乌韦, 对不起,这是愚蠢的,但我不明白这将有什么区别,因为我的字符串包含引号,即 “--header = \'主机:mywebsite.com:9090 \' 您能否扩展我将如何在数组中输入变量值,以便可以读取引号Bash是什么意思? – dhevans79 2013-05-06 12:36:44
或者是我使用的格式正确,并且通过使用数组,Bash将开始正确解释它们? – dhevans79 2013-05-06 12:37:37
定义'session =( - header ='Host:mywebsite.com:9090'--header ='User-Agent:... Firefox/20.0')'然后使用'“$ {session [@]}” '而不是'$ session'。其他变量必须进行类似的修改。 – Uwe 2013-05-06 12:42:55