1+ from dotenv import load_dotenv
2+ load_dotenv ()
3+ import os
4+ from selenium import webdriver
5+ from selenium .webdriver .chrome .options import Options
6+ from selenium .webdriver .support .wait import WebDriverWait
7+ from selenium .webdriver .support import expected_conditions as EC
8+ from selenium .webdriver .common .by import By
9+ import time
10+ import random
11+ from selenium .webdriver .common .action_chains import ActionChains
12+
13+ class ReplitScrapper ():
14+ def __init__ (self ):
15+ chrome_options = Options ()
16+ chrome_options .add_argument ('incognito' )
17+ chrome_options .add_argument ("--window-size=1920,1080" )
18+ # chrome_options.add_argument("--headless")
19+ user_agent = 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.50 Safari/537.36'
20+ chrome_options .add_argument (f'user-agent={ user_agent } ' )
21+ driver = webdriver .Chrome (options = chrome_options )
22+ self .driver = driver
23+
24+ # def login(self) -> None:
25+ # self.driver.get(os.environ['LOGINURL'])
26+ # wait = WebDriverWait(self.driver, 10)
27+ # email = wait.until(EC.visibility_of_element_located((By.ID, "1val-input")))
28+ # time.sleep(random.randint(2, 5))
29+ # email.send_keys(os.environ['EMAIL'])
30+ # password = wait.until(EC.visibility_of_element_located((By.ID, "2val-input")))
31+ # time.sleep(random.randint(2, 5))
32+ # password.send_keys(os.environ['PASSWORD'])
33+ # submit_button = wait.until(EC.visibility_of_element_located((By.XPATH, "//button[@type='submit']")))
34+ # time.sleep(random.randint(2, 5))
35+ # action = ActionChains(self.driver)
36+ # action.move_to_element(submit_button)
37+ # action.click()
38+
39+ def get_file_list (self ) -> list :
40+ result = []
41+ wait = WebDriverWait (self .driver , 10 )
42+ showcode_button = wait .until (EC .visibility_of_element_located ((By .XPATH , "//div[@class='css-148day7']/span[@class='css-36v8q4']/button[@type='button']" )))
43+ time .sleep (random .randint (2 , 5 ))
44+ action = ActionChains (self .driver )
45+ action .move_to_element (showcode_button )
46+ action .click ()
47+ files = wait .until (EC .visibility_of_element_located ((By .XPATH , "//div[@role='treeitem']/preceding-sibling::div" )))
48+ if len (files ) != 0 :
49+ for file in files :
50+ result .append (file .div .get_attribute ('title' ))
51+ else :
52+ print ("File list not found." )
53+ return result
54+
55+ def cleanup (self ) -> None :
56+ self .driver .quit ()
0 commit comments