-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
156 lines (109 loc) · 4.29 KB
/
main.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
from unittest import result
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.support.ui import WebDriverWait
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.support import expected_conditions as EC
from time import sleep
from msvcrt import getche, getch
import os
chrome_options = Options()
chrome_options.headless = True
# Deprecated Version:-
# driver = webdriver.Chrome("C:/ProgramData/chocolatey/lib/chromedriver/tools/chromedriver.exe", options=chrome_options)
driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()), options=chrome_options)
print("Seed String: ", end="")
kws = "+".join(input().split())
url = "https://www.google.com/search?q=%22{}%22".format(kws)
driver.get(url)
delay = 10 # seconds
try:
myElem = WebDriverWait(driver, delay).until(EC.presence_of_element_located((By.ID, 'rso')))
print ("Page is ready!")
except TimeoutException:
print ("Loading took too much time!")
print("Results Loaded in {}".format(driver.find_element(By.XPATH, value="//*[@id=\"result-stats\"]/nobr").text))
# a = []
# for nresults in range(1,5):
# target = "//*[@id=\"rso\"]/div[{}]/div".format(nresults) #/div/div[2]/div
# a.append(driver.find_element(By.XPATH, value=target).text)
# a.append(driver.find_element(By.XPATH, value='//*[@id="rso"]/div[2]/div/div[2]/div').text)
# a.append(driver.find_element(By.XPATH, value='//*[@id="rso"]/div[3]/div/div[2]/div').text)
# a.append(driver.find_element(By.XPATH, value='//*[@id="rso"]/div[4]/div/div[2]/div').text)
# a.append(driver.find_element(By.XPATH, value='//*[@id="rso"]/div[5]/div/div[2]/div').text)
# a.append(driver.find_element(By.XPATH, value='//*[@id="rso"]/div[6]/div/div[2]/div').text)
try:
videsc = driver.find_elements(By.CLASS_NAME, value="Uroaid")
# description += " Generated by Descriptionatoronicalyzer"
except:
pass
try:
description = str(driver.find_element(By.CLASS_NAME, value="kno-rdesc").text)[12:]
# description += " Generated by Descriptionatoronicalyzer"
except:
pass
a = driver.find_elements(By.CSS_SELECTOR, value="div.VwiC3b.yXK7lf.MUxGbd.yDYNvb.lyLwlc.lEBKkf")
b = driver.find_elements(By.CSS_SELECTOR, value=".NJo7tc.Z26q7c.uUuwM span:nth-child(2)")
results = []
if videsc:
results = videsc + a + b
else:
results = a + b
try:
if description:
results.insert(0,description)
except:
pass
# div.IsZvec > div.VwiC3b.yXK7lf.MUxGbd.yDYNvb.lyLwlc.lEBKkf
print("\n\nFollowing are GPT-3 generated Keywords. Enjoy! ;)\n\n")
i=1
for j in results:
try:
print("[{}]>>> {}\n".format(i,j.text))
except:
print("[{}]>>> {}\n".format(i,j))
i+=1
driver.find_element(By.XPATH, value="//*[@id=\"xjs\"]/table/tbody/tr/td[3]/a").click()
print("\n\n\n\n\nNow you are on second page Good luck!!!!!!!!!!!!!\n\n\n\n\n\n\n")
delay = 10 # seconds
try:
myElem = WebDriverWait(driver, delay).until(EC.presence_of_element_located((By.ID, 'rso')))
print ("Page is ready!")
except TimeoutException:
print ("Loading took too much time!")
print("Results Loaded in {}".format(driver.find_element(By.XPATH, value="//*[@id=\"result-stats\"]/nobr").text))
try:
videsc1 = driver.find_elements(By.CLASS_NAME, value="Uroaid")
# description += " Generated by Descriptionatoronicalyzer"
except:
pass
try:
description1 = str(driver.find_element(By.CLASS_NAME, value="kno-rdesc").text)[12:]
# description += " Generated by Descriptionatoronicalyzer"
except:
pass
a1 = driver.find_elements(By.CSS_SELECTOR, value="div.VwiC3b.yXK7lf.MUxGbd.yDYNvb.lyLwlc.lEBKkf")
b1 = driver.find_elements(By.CSS_SELECTOR, value=".NJo7tc.Z26q7c.uUuwM span:nth-child(2)")
results1 = []
if videsc1:
results1 = videsc1 + a1 + b1
else:
results1 = a1 + b1
try:
if description1:
results1.insert(0,description1)
except:
pass
# div.IsZvec > div.VwiC3b.yXK7lf.MUxGbd.yDYNvb.lyLwlc.lEBKkf
print("\n\nFollowing are GPT-3 generated Keywords. Enjoy! ;)\n\n")
i=1
for j1 in results1:
try:
print("[{}]>>> {}\n".format(i,j1.text))
except:
print("[{}]>>> {}\n".format(i,j1))
i+=1
driver.quit()