Windows Script Batch URL Encoding

I have a windows script package that I use for a quick Google search. However, I cannot figure out how to generally encode special characters. For example, if I try to find C #, the pound sign will break it. Here is my code:

SET q="https://www.google.com/#q=%*"
SET q=%q: =+%
chrm %q%
+4
source share
2 answers

Without installing any external tools:

@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%
+6
source

, Windows bat script. Python - , , -, . Windows, powershell script, . Python 3 script , , , , .

import sys
import subprocess
import urllib.parse

browser = sys.argv[1]
browserParms = sys.argv[2]

queryString = " ".join(sys.argv[3:])
queryString = urllib.parse.quote(queryString)
url = "https://www.google.com/#q=" + queryString

subprocess.Popen([browser, browserParms, url])

sys.exit()

script Linux, . - Windows. goog ( , , :))

#!/bin/bash
python3 /home/justin/Dropbox/MyFiles/Programs/CrossPlatform/Python3/GoogleSearch.py "firefox" "-new-window" "$@"

, script $PATH. "" " ".

goog i like turtles
+8

Source: https://habr.com/ru/post/1627202/


All Articles