我正在嘗試訪問 reddit.com,執行一項操作,然后訪問 old.reddit.com 并比較結果。我無法訪問 old.reddit.com,因為它重定向到 reddit.com。我該如何防止這種情況?
這是我的代碼
ChromeOptions ops = new ChromeOptions();
ops.addArguments("--disable-notifications", "start-maximized", "--disable-popup-blocking");
WebDriver driver = new ChromeDriver(ops);
driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(7));
driver.get("https://www.reddit.com");
WebElement e =driver.findElement(By.name("q"));
e.sendKeys("New York");
Thread.sleep(2000);
e.sendKeys(Keys.RETURN);
Thread.sleep(2000);
driver.navigate().to("http://www.old.reddit.com/");
當我收到安全警告時,我嘗試不使用 ChromeOptions 并單擊接受。我已經嘗試過隱身我能想到的任何其他解決方法,但我一直卡住。
uj5u.com熱心網友回復:
正確的 URL 即https://old.reddit.com/。您在 http 中缺少“s”并在 URL 中添加了額外的“www”
這
driver.navigate().to("https://old.reddit.com/");在我的想法中很好用;
uj5u.com熱心網友回復:
您的舊 reddit 鏈接缺少 http 上的“s”。 https://old.reddit.com/
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/473010.html
上一篇:如何在重定向之前在Next.js中設定flash變數?
下一篇:沒有檔案夾和檔案擴展名的重寫規則
