1616public class Scraper {
1717 private static final String USERNAME = "" ; // Provide your LeetCode username
1818 private static final String PASSWORD = "" ; // Provide your LeetCode password
19+ public static final int QUESTIONS_PAGE_WAIT_MILLIS = 25000 ;
20+ public static final int LOGIN_PAGE_WAIT_MILLIS = 2000 ;
1921 WebDriver driver ;
2022 List <String > companyURLs = new ArrayList <>();
2123
@@ -31,7 +33,7 @@ public void setup() throws InterruptedException, IOException {
3133 driver .findElement (By .xpath ("// *[ @ id = 'id_login']" )).sendKeys (USERNAME );
3234 driver .findElement (By .xpath ("// *[ @ id = 'id_password']" )).sendKeys (PASSWORD );
3335 driver .findElement (By .xpath ("// *[ @ id = 'id_password']" )).sendKeys (Keys .ENTER );
34- Thread .sleep (2000 ); // Wait for the login to happen, then visit the problems pages
36+ Thread .sleep (LOGIN_PAGE_WAIT_MILLIS ); // Wait for the login to happen, then visit the problems pages
3537 driver .get ("https://leetcode.com/problemset/all/" );
3638 List <WebElement > companies = driver .findElements (By .cssSelector (".mb-4.mr-3" ));
3739 for (WebElement company : companies ) {
@@ -48,7 +50,7 @@ private void visitCompanies(String companyURL) throws InterruptedException, IOEx
4850 String companyName = companyURL .substring (companyURL .lastIndexOf ("/" ) + 1 );
4951 System .out .println ("Visiting " + companyURL );
5052 driver .get (companyURL );
51- Thread .sleep (25000 ); // Wait for the page to load, for companies like Google/Amazon, it takes a lot of time
53+ Thread .sleep (QUESTIONS_PAGE_WAIT_MILLIS ); // Wait for the page to load, for companies like Google/Amazon, it takes a lot of time
5254 String table = "" ;
5355 try {
5456 table = "<table>" + driver .findElement (By .className ("table" )).getAttribute ("innerHTML" ) + "</table>" ;
0 commit comments