2022-10-13 15:34:52 +00:00
|
|
|
import webbrowser
|
|
|
|
from sys import argv
|
2022-10-13 16:03:06 +00:00
|
|
|
from urllib.parse import parse_qs, quote
|
2022-10-13 15:34:52 +00:00
|
|
|
|
|
|
|
import requests
|
|
|
|
from bs4 import BeautifulSoup
|
2022-10-13 16:03:06 +00:00
|
|
|
from fake_useragent import UserAgent
|
2022-10-13 15:34:52 +00:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
if len(argv) > 1:
|
|
|
|
query = "%20".join(argv[1:])
|
|
|
|
else:
|
|
|
|
query = quote(str(input("Search: ")))
|
|
|
|
|
|
|
|
print("Googling.....")
|
|
|
|
|
|
|
|
url = f"https://www.google.com/search?q={query}&num=100"
|
|
|
|
|
|
|
|
res = requests.get(
|
|
|
|
url,
|
2022-10-13 16:03:06 +00:00
|
|
|
headers={"User-Agent": str(UserAgent().random)},
|
2022-10-13 15:34:52 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
try:
|
|
|
|
link = (
|
|
|
|
BeautifulSoup(res.text, "html.parser")
|
|
|
|
.find("div", attrs={"class": "yuRUbf"})
|
|
|
|
.find("a")
|
|
|
|
.get("href")
|
|
|
|
)
|
|
|
|
|
|
|
|
except AttributeError:
|
|
|
|
link = parse_qs(
|
|
|
|
BeautifulSoup(res.text, "html.parser")
|
|
|
|
.find("div", attrs={"class": "kCrYT"})
|
|
|
|
.find("a")
|
|
|
|
.get("href")
|
|
|
|
)["url"][0]
|
|
|
|
|
|
|
|
webbrowser.open(link)
|