Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- args={...}
- function search(args1,args2,args3)
- function stringReplace(source,delString,repString)
- if string.find(source,delString) then
- local stringPos={string.find(source,delString)}
- source=string.sub(source,1,stringPos[1]-1)..repString..string.sub(source,stringPos[2]+1)
- end
- return(source)
- end
- function stringReplaceAll(source,delString,repString)
- while string.find(source,delString) do
- local stringPos={string.find(source,delString)}
- source=string.sub(source,1,stringPos[1]-1)..repString..string.sub(source,stringPos[2]+1)
- end
- return(source)
- end
- function stringDel(source,delString)
- local stringPos={string.find(source,delString)}
- source=string.sub(source,1,stringPos[1]-1)..string.sub(source,stringPos[2]+1)
- return(source)
- end
- function stringDelAll(source,delString)
- while string.find(source,delString) do
- source=stringDel(source,delString)
- end
- return source
- end
- results={}
- url=http.get("http://www.bing.com/search?q="..stringReplaceAll(args1,' ','+'))
- html=url.readAll()
- i=255
- while i>=0 do
- html=stringDelAll(html,"&#"..tostring(i)..';')
- i=i-1
- end
- html=stringDelAll(html,"<strong>")
- html=stringDelAll(html,"</strong>")
- html=stringDelAll(html,""")
- html=stringDelAll(html,';')
- html=stringDelAll(html,':')
- i=1
- while string.find(html,"<p>") do
- local stringPos1={string.find(html,"<p>")}
- local stringPos2={string.find(html,"</p>")}
- results[i]=string.sub(html,stringPos1[2]+1,stringPos2[1]-1)
- html=stringDel(html,"<p>")
- html=stringDel(html,"</p>")
- i=i+1
- end
- amount=4
- if args2 then
- amount=tonumber(args2)
- end
- num=nil
- if tonumber(args3)==nil then
- for i=1,amount do
- print("Result:"..i)
- print(results[i])
- end
- else
- num=tonumber(args3)
- print(results[num])
- end
- end
- search(args[1],5)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement