selenium 拦截网站数据,爬虫处理js

    xiaoxiao2021-04-14  37

    ((RemoteWebDriver) driver).executeScript( "window.getJSON=$.getJSON;$.getJSON=function(){ window.funObj=arguments[2]; var myFun=function(data){ window.myData=data;} ; window.getJSON(arguments[0],arguments[1],myFun) }"); driver.findElement(By.id("submit")).click(); try { WebDriverWait wait = new WebDriverWait(driver, 10); @SuppressWarnings("unchecked") Map<String, ?> data = (Map<String, ?>) wait.until(new Function<WebDriver, Object>() { public Object apply(@Nullable WebDriver driver) { return ((RemoteWebDriver) driver).executeScript("return window.myData;"); } }); ((RemoteWebDriver) driver) .executeScript("window.funObj(window.myData);delete window.myData;$.getJSON=window.getJSON;"); if (!"0".equals(data.get("code"))) { return new Result(Constants.INPUTERROR, data.get("desc")); } return new Result(Constants.SUCCESS, data.get("desc")); } catch (Exception e) { e.printStackTrace(); return new Result(Constants.SYSTEMERROR, Constants.getMessage(Constants.SYSTEMERROR)); }
    转载请注明原文地址: https://ju.6miu.com/read-670420.html

    最新回复(0)