调用百度百科查询关键词(默认快捷键#z)

#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
}

给TA捐赠
共{{data.count}}人
人已捐赠
其他

调用控制面板里的项目

2020-3-9 5:41:44

其他

调色板对话框

2020-3-9 5:43:44

个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索