wget 转义特殊字符

2023-12-24

我正在尝试使用 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:'')))

由于特殊字符,它不起作用。我试图用“\”来逃避它们,但这对我不起作用。


由于搜索查询仅使用单引号,因此您可以使用双引号来保护它们免受 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:'')))
.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

wget 转义特殊字符 的相关文章

随机推荐