DEV Community

hubs
hubs

Posted on

Getting this Code Running in colab

Getting issues while trying to run this in colab. Which
Methode should be addet. Cloudflare issues stand in the way.

rom selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from pynput.mouse import Controller, Button
import keyboard as kb
import time 


driver = webdriver.Chrome()
options = webdriver.ChromeOptions()
options.add_experimental_option("excludeSwitches", ['enable-automation'])
options.add_extension(r'D:\\Coding Projects\\Python_GoogleMaps_Scraping\\instantdatascraper.crx')
driver = webdriver.Chrome(options=options)
driver.maximize_window()
wait = WebDriverWait(driver, 20)

#Marks how much time will it take before "next step". Adjust based on your needs
t1 = 4
t2 = 5
t3 = 10
t4 = 150 #EDIT BASED ON YOUR NEEDS

#Industry you want to on Clutch in our case cybersecurity industry
url = driver.get('https://clutch.co/it-services/cybersecurity')
time.sleep(t2)

#We are setting up mouse function from pynput
mouse = Controller()

#Get to the bottom of the page
mouse.scroll(0, -165)
time.sleep(t1)

#Closing popout
mouse.position = (1231, 357)
mouse.click(Button.left, 2)
time.sleep(t2)

#Mouse cordinates pointing to the Extension part 
mouse.position = (1795, 62)
mouse.click(Button.left, 1)
time.sleep(t2)

#Mouse cordinates opening the Instant Data Scraper
mouse.position = (1600, 214)
mouse.click(Button.left, 1

)
time.sleep(t2)

#Click on next button option
mouse.position = (235, 160)
mouse.click(Button.left)
time.sleep(t1)

#Locate next button
mouse.position = (1130, 772)
mouse.click(Button.left)
time.sleep(t1)

#Get back into instant data scraper view
kb.press_and_release('alt+tab')
time.sleep(t1)

#Edit delay if needed
#mouse.position = (249, 229)
#mouse.click(Button.left, 2)
#buffer_to_add = '9'
#kb.write(buffer_to_add, 0.1)
#time.sleep(t1)

#Click start crawling
mouse.position = (244, 162)
mouse.click(Button.left, 1)
time.sleep(t2)

#Edit based on your needs 
time.sleep(t4)

#Export to XLSM
mouse.position = (401, 135)
mouse.click(Button.left, 1)

time.sleep(t2)

print('You are done!')
Enter fullscreen mode Exit fullscreen mode

I am Not able to run this in colab

Top comments (0)