wget转义特殊字符 [英] wget escape special characters

查看:124
本文介绍了wget转义特殊字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用wget下载此网页的内容:

I am trying to download the content of this webpage with 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:'')))

由于特殊字符,它不起作用.我试图用"\"将其转义,但对我而言不起作用.

It doesn't work because of the special characters. I have tried to escape them with "\", but it doesn't work for me.

推荐答案

由于搜索查询仅使用单引号,因此可以使用双引号保护它们免受shell攻击.另外,在zsh(可能还有其他交互式shell)中,您需要用反斜杠转义字符,因为甚至在双引号内也具有含义.结果看起来像这样:

Since the search query only uses single quotes, you can use double quotes to protect them from the shell. In addition, in zsh (and possibly other interactive shells) you need to escape the ! character with a backslash, since ! has meaning even inside double quotes. The result looks like this:

# 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而无需特殊引号:

To avoid such problems, you can use wget -i to specify an input file, where the URLs will be read line by line without interpretation of special characters (except for the newline character, which separates the lines). In conjunction with the << operator, it allows specifying the URL without special quoting:

# 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:'')))
.

这篇关于wget转义特殊字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆