由于搜索查询仅使用单引号,因此您可以使用双引号来保护它们免受 shell 的影响。此外,在 zsh (以及可能的其他交互式 shell)中,您需要转义!
带有反斜杠的字符,因为!
即使在双引号内也有意义。结果如下:
# use double quotes and escape "!"
wget "https://bibliotheque-numerique.paris.fr/search.aspx?SC=DEFAULT#/Search/(query:(ForceSearch:\!f,Page:0,PageRange:3,QueryString:':',ResultSize:50,ScenarioCode:DEFAULT,ScenarioDisplayMode:display-standard,SearchLabel:'',SearchTerms:'',SortField:DateOfInsertion_sort,SortOrder:0,TemplateParams:(Scenario:'',Scope:VPCO,Size:\!n,Source:'',Support:'')))"
为了避免此类问题,您可以使用wget -i
指定一个输入文件,其中的 URL 将被逐行读取,而不解释特殊字符(分隔行的换行符除外)。结合<<
运算符,它允许指定 URL 而无需特殊引用:
# use -i - to read from stdin, and the <<\ operator to feed
# the URL to Wget without having to quote it
wget -i - <<\.
https://bibliotheque-numerique.paris.fr/search.aspx?SC=DEFAULT#/Search/(query:(ForceSearch:!f,Page:0,PageRange:3,QueryString:':',ResultSize:50,ScenarioCode:DEFAULT,ScenarioDisplayMode:display-standard,SearchLabel:'',SearchTerms:'',SortField:DateOfInsertion_sort,SortOrder:0,TemplateParams:(Scenario:'',Scope:VPCO,Size:!n,Source:'',Support:'')))
.