Advertisement
ecco7777

CC Bing Search

May 23rd, 2017
395
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.72 KB | None | 0 0
  1. args={...}
  2. function search(args1,args2,args3)
  3.  
  4. function stringReplace(source,delString,repString)
  5. if string.find(source,delString) then
  6. local stringPos={string.find(source,delString)}
  7. source=string.sub(source,1,stringPos[1]-1)..repString..string.sub(source,stringPos[2]+1)
  8. end
  9. return(source)
  10. end
  11.  
  12. function stringReplaceAll(source,delString,repString)
  13. while string.find(source,delString) do
  14. local stringPos={string.find(source,delString)}
  15. source=string.sub(source,1,stringPos[1]-1)..repString..string.sub(source,stringPos[2]+1)
  16. end
  17. return(source)
  18. end
  19.  
  20. function stringDel(source,delString)
  21. local stringPos={string.find(source,delString)}
  22. source=string.sub(source,1,stringPos[1]-1)..string.sub(source,stringPos[2]+1)
  23. return(source)
  24. end
  25.  
  26. function stringDelAll(source,delString)
  27. while string.find(source,delString) do
  28. source=stringDel(source,delString)
  29. end
  30. return source
  31. end
  32.  
  33. results={}
  34. url=http.get("http://www.bing.com/search?q="..stringReplaceAll(args1,' ','+'))
  35. html=url.readAll()
  36.  
  37. i=255
  38. while i>=0 do
  39. html=stringDelAll(html,"&#"..tostring(i)..';')
  40. i=i-1
  41. end
  42.  
  43. html=stringDelAll(html,"<strong>")
  44. html=stringDelAll(html,"</strong>")
  45. html=stringDelAll(html,"&quot")
  46. html=stringDelAll(html,';')
  47. html=stringDelAll(html,':')
  48.  
  49. i=1
  50. while string.find(html,"<p>") do
  51. local stringPos1={string.find(html,"<p>")}
  52. local stringPos2={string.find(html,"</p>")}
  53. results[i]=string.sub(html,stringPos1[2]+1,stringPos2[1]-1)
  54. html=stringDel(html,"<p>")
  55. html=stringDel(html,"</p>")
  56. i=i+1
  57. end
  58. amount=4
  59. if args2 then
  60. amount=tonumber(args2)
  61. end
  62. num=nil
  63. if tonumber(args3)==nil then
  64. for i=1,amount do
  65. print("Result:"..i)
  66. print(results[i])
  67. end
  68. else
  69. num=tonumber(args3)
  70. print(results[num])
  71. end
  72. end
  73.  
  74. search(args[1],5)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement