Google Search Api

许多实用脚本和封装函数, 可以让您编写脚本更加便捷高效
arcticir
Posts: 543
Joined: 17 Nov 2013, 11:32

Google Search Api

26 Aug 2016, 02:11

旧的股沟搜索API不能用了,捕获新API一枚.
相较旧接口最大8条结果,现在最多100,和直接读取网页一样.不过它的数据体积更小(大概只有网页的一半大小),而且也没有频繁的安全认证.
唯一可惜的是,获取的不是纯正的JSON数据,提取有些麻烦.
相关函数,论坛都有.

Code: Select all

google_searchApi(s,m:=15){
	s:=oh("https://www.google.com/search?tch=1&num=" (m+4) "&fp=996a8bf623963639&q=" Uri(s) ,"127.0.0.1:8118")
	g:=[]
	for i,n in str_o(s,"\x3cdiv class\\x3d\\x22g\\x22\\x3e\\x3c!--m--","!--n--")
	{
	for d,b in {"\b":Chr(08),"\\":"\","\/":"/","\t":"`t","\n":"`n","\f":Chr(12),"\r":"`r","\`"":"`""}
		if instr(n,d)
			StrReplace,n,%n%,%d%,%b%
		n:=decode_all(n)
		u:=str_s(n,"><a href=`"","`"")
		t:=str_s(n,">","</a></h3")
		c:=str_s(n,"class=`"st`">","</span><")
		if instr(c,"<span class=")
		{
			StrReplace,c,%c%,<span class="f">
			StrReplace,c,%c%,</span>
		}
		if instr(c,"<em>")
		{
			StrReplace,c,%c%,<em>
			StrReplace,c,%c%,</em>
		}
			StrReplace,c,%c%,<wbr>
		g.push({url:u,title:t,st:c})
	}
	Return g.Length()>m?g.RemoveAt(m+1,g.Length()-m):"",g
}

Return to “脚本函数”

Who is online

Users browsing this forum: No registered users and 4 guests