VBS脚本调用百度浏览器查询中文时可能存在编码问题。VBS脚本默认使用的是ANSI编码,而百度浏览器可能使用的是UTF-8编码。为了解决这个问题,可以在VBS脚本中添加一行代码,将查询的中文进行编码转换。

下面是一个示例代码:

Dim objShell
Set objShell = CreateObject("WScript.Shell")

' 查询的中文内容
Dim searchContent
searchContent = "你好"

' 将中文内容进行编码转换
Dim encodedContent
encodedContent = URLEncode(searchContent)

' 构造查询的URL
Dim searchURL
searchURL = "https://www.baidu.com/s?wd=" & encodedContent

' 调用百度浏览器打开查询结果
objShell.Run "baidu.exe " & searchURL

' 编码转换函数
Function URLEncode(str)
    Dim i, strTemp, strChar
    strTemp = ""
    For i = 1 To Len(str)
        strChar = Mid(str, i, 1)
        If strChar = " " Then
            strTemp = strTemp & "+"
        ElseIf InStr("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_.~", strChar) > 0 Then
            strTemp = strTemp & strChar
        Else
            strTemp = strTemp & "%" & Hex(Asc(strChar))
        End If
    Next
    URLEncode = strTemp
End Function

在上述代码中,使用了URLEncode函数对中文进行编码转换。然后将编码后的内容拼接到百度查询的URL中,最后通过objShell.Run方法调用百度浏览器打开查询结果。

请注意,以上代码仅适用于调用百度浏览器。如果要调用其他浏览器或搜索引擎,请根据其不同的URL格式进行相应的修改。

VBS脚本调用百度浏览器查询为啥不能识别中文

原文地址: https://www.cveoy.top/t/topic/hZ4b 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录