Skip to content

Commit

Permalink
Merge pull request #13 from codewithnick/google_search
Browse files Browse the repository at this point in the history
fixed google search result
  • Loading branch information
codewithnick committed Jun 7, 2024
2 parents 5e728f1 + 749eed4 commit af24328
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/searchenginepy/Google/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#google class which has functions to search and get results
import requests
import bs4
from urllib.parse import urlparse
class Google():
def __init__(self):
"""_summary_
Expand Down Expand Up @@ -35,11 +36,17 @@ def search(self,query ,pagenumber=1) -> list:
return links
def cleanlinks(self,links):
#clean links
links=[i for i in links if i is not None]
if self.httpallowed:
links=[i for i in links if i.startswith('http')]
else:
links=[i for i in links if i.startswith('https')]
return links
clean_links=[]
for i in links:
if(i==None or 'http' not in i):
continue
position = i.find('http')
i=i[position:]
result = urlparse(i)
# A valid URL should have at least a scheme and netloc
if(not result.scheme or not result.netloc):
continue
clean_links.append(i)
return clean_links
def getresponse(self):
return self.results

0 comments on commit af24328

Please sign in to comment.