-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.py
More file actions
45 lines (39 loc) · 1.59 KB
/
main.py
File metadata and controls
45 lines (39 loc) · 1.59 KB
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
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from webdriver_manager.chrome import ChromeDriverManager
class GoogleKeywordScreenshooter:
def __init__(self, keyword, screenshots_dir):
self.browser = webdriver.Chrome(ChromeDriverManager().install())
self.keyword = keyword
self.screenshots_dir = screenshots_dir
def start(self):
self.browser.get("https://google.com")
search_bar = self.browser.find_element_by_class_name("gLFyf")
search_bar.send_keys(self.keyword)
search_bar.send_keys(Keys.ENTER)
try:
shitty_element = WebDriverWait(self.browser, 10).until(
EC.presence_of_element_located(By.CLASS_NAME, "g-blk")
)
self.browser.execute_script(
"""
const shitty = arguments[0];
shitty.parentElement.removeChild(shitty)
""",
shitty_element,
)
except:
pass
search_results = self.browser.find_elements_by_class_name("g")
for index, search_result in enumerate(search_results):
search_result.screenshot(
f"{self.screenshots_dir}/{self.keyword}x{index}.png"
)
def finish(self):
self.browser.quit()
domain_competitors = GoogleKeywordScreenshooter("buy domain", "screenshots")
domain_competitors.start()
domain_competitors.finish()