#SingleInstance force #z:: ;默认快捷键 #z pwb := ComObjCreate("InternetExplorer.Application") pwb.visible := false pwb.ToolBar := false InputBox,query_ori,输入查询关键词 pwb.navigate("https://baike.baidu.com/search/none?word=" . CustomFunction_SkSub_UrlEncode(query_ori)) while pwb.ReadyState !=4 Sleep 100 url_href := pwb.document.querySelectorAll("#body_wrapper > div.searchResult > dl > dd:nth-child(2) > a")[0].getAttribute("href") ;~ MsgBox % url_href IfInString,url_href,www.baidu.com { sumarry := "百度百科未收录该词条。" MsgBox % sumarry return } pwb.navigate(url_href) while pwb.ReadyState !=4 Sleep 100 result := pwb.document.querySelectorAll("body > div.body-wrapper > div.content-wrapper > div > div.main-content")[0].innerText result := RegExReplace(result, "(*BSR_ANYCRLF)R+", "`n") ;删除空行 result := RegExReplace(result, "(s+)R+", "`n") ;删除只含有空白字符的空行 try sumarry := pwb.document.querySelectorAll("body > div.body-wrapper > div.content-wrapper > div > div.main-content > div.lemma-summary")[0].innerText catch e { try sumarry := pwb.document.querySelectorAll("#posterCon > dd.desc > div")[0].innerText catch e { sumarry := pwb.document.querySelectorAll("body > div.body-wrapper.feature.large-feature.movieLarge > div.feature-poster > div > div.layout.lemmaWgt-posterBg > div.poster-top > div")[0].innerText } } MsgBox % sumarry return CustomFunction_SkSub_UrlEncode(str, enc="UTF-8") { enc:=trim(enc) If enc= Return str hex := "00", func := "msvcrt" . (A_IsUnicode ? "swprintf" : "sprintf") VarSetCapacity(buff, size:=StrPut(str, enc)), StrPut(str, &buff, enc) While (code := NumGet(buff, A_Index - 1, "UChar")) && DllCall(func, "Str", hex, "Str", "%%%02X", "UChar", code, "Cdecl") encoded .= hex Return encoded }