python - Windows 批处理脚本中的 URL 编码

标签 python linux windows batch-file

我有一个 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/

相关文章:

php - 打开批处理文件php

php - 使用 session 时在 xampp 上可能导致 ERR_CONNECTION_RESET 错误的原因

python - Django 无法检测模型字段的存在

python - 查找具有轮廓的对象的旋转

Python 嵌套 'while' 循环未正确执行

c++ - 在 C++ 中嵌入 Python - 从 C++ 程序运行 Python

linux - 如何获取/etc/security/limits.conf 更改反射(reflect)在 headless 用户下运行的进程?

java - JAVA中发送ctrl+c关闭ping请求

c - 如何在 Windows 上用 C 语言从另一个程序启动一个独立的程序(在单独的控制台窗口中)?

linux - SVN checkout 失败,svn ://protocol but it is working with svn+ssh://protocol