forked from codewithnick/searchenginepy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.py
59 lines (55 loc) · 2.27 KB
/
example.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
##################################################################
# IMPORTING MODULES
##################################################################
from searchenginepy.Bing import Bing
from searchenginepy.Google import Google
from searchenginepy.DuckDuckGo import Duckduckgo
from searchenginepy.Brave import Brave
from searchenginepy import SearchEngine
################################################################
PAGE_NUMBER=1
TOP_RESULT_STRING='Top result for page number:'
################################################################
# USING SEARCH ENGINE CLASS
###############################################################
searchengine = SearchEngine("search engine",PAGE_NUMBER)
obj1=searchengine.google()
obj2=searchengine.bing()
obj3=searchengine.duckduckgo()
obj4=searchengine.brave()
if(len(obj1)>0):
print(TOP_RESULT_STRING,PAGE_NUMBER,' from google:', "www.google.com"+obj1[15])
else:
print('No results from google')
if(len(obj2)>0):
print(TOP_RESULT_STRING,PAGE_NUMBER,' from bing:',obj2[30]) #Does not work
else:
print('No results from bing')
if(len(obj3)>0):
print(TOP_RESULT_STRING,PAGE_NUMBER,' from duckduckgo:',obj3[0]) #Does not work
else:
print('No results from duckduckgo')
if(len(obj4)>0):
print(TOP_RESULT_STRING,PAGE_NUMBER,' from brave:',obj4[10])
else:
print('No results from brave')
#################################################################
# USING SPECIFIC SEARCH ENGINES
#################################################################
PAGE_NUMBER=2
googleobj=Google()
res=googleobj.search('google',PAGE_NUMBER)
if(len(res)>0):
print(TOP_RESULT_STRING,PAGE_NUMBER,' from google:', "www.google.com"+obj1[15])
braveobj=Brave()
res=braveobj.search('brave',PAGE_NUMBER)
if(len(res)>0):
print(TOP_RESULT_STRING,PAGE_NUMBER,' from brave:',res[10])
duckduckgoobj=Duckduckgo()
res=duckduckgoobj.search('duckduckgo',PAGE_NUMBER)
if(len(res)>0):
print(TOP_RESULT_STRING,PAGE_NUMBER,' from duckduckgo:',res[0]) #Does not work
bingobj=Bing()
res=bingobj.search('bing',PAGE_NUMBER)
if(len(res)>0):
print(TOP_RESULT_STRING,PAGE_NUMBER,' from bing:',res[0]) #Does not work, output array same as for page 1