我有一个 Windows 批处理脚本,可用于快速进行 Google 搜索。但是,我不知道如何对特殊字符进行通用编码。就像我尝试搜索 C# 一样,井号会破坏它。这是我的代码:
SET q="https://www.google.com/#q=%*"
SET q=%q: =+%
chrm %q%
最佳答案
无需安装任何外部工具:
@echo off
setlocal
set "string=gibberish+?blahblah@"
:: Define simple macros to support JavaScript within batch
set "beginJS=mshta "javascript:code(close(new ActiveXObject('Scripting.FileSystemObject').GetStandardStream(1).Write("
set "endJS=)));""
:: FOR /F does not need pipe
for /f %%N in (
'%beginJS% encodeURIComponent("%string%") %endJS%'
) do set encoded=%%N
echo %string% -^> %encoded%
关于python - Windows 批处理脚本中的 URL 编码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35186560/