Jsoup не может извлечь для меня содержимое логина html - PullRequest
0 голосов
/ 04 августа 2020

enter image description hereI am running into a problem where in I need to extract DOM html for login window for website https://webuy.com Я попытался с кодом ниже выполнить очистку для входа в систему, но не смог:

Document document = Jsoup.connect(url).timeout(0).get();
        System.out.println(document.toString());
     Element textField = document.getElementsByClass("login-form"); 
or Element textField = loginDoc.select("div").first();

Я не получить html содержимое окна входа в систему, а я получаю содержимое html за модальным входом. Пожалуйста, кто-нибудь посоветуйте мне, что может быть решением этой проблемы. Заранее спасибо!

1 Ответ

0 голосов
/ 06 августа 2020

Я нашел способ получить динамическое c html содержимое:

  WebElement elem = driver.findElement(By.xpath("//*"));
    String html = elem.getAttribute("innerHTML");

readPropertiesFile(System.getProperty("user.dir")+"/src/dynamicObjectRepo/OR.properties");
        writePropertiesFile(System.getProperty("user.dir")+"/src/dynamicObjectRepo/OR.properties", locatorAction ,html);
    // custom file to write the html content to properties fie
public static Properties writePropertiesFile(String fileName, String variableLocator, String genericXpath) throws IOException {
        FileOutputStream out = new FileOutputStream(fileName);
        try {
            prop.setProperty(variableLocator, genericXpath);
            prop.store(out, null);
            out.close();
        } catch(FileNotFoundException fnfe) {
            fnfe.printStackTrace();
        } catch(IOException ioe) {
            ioe.printStackTrace();
        } finally {
            out.close();
        }
        return prop;
    }
Now i have got the whole html content of the page which includes login form contents as well. I can extract now the textfield by using jsoup methods.
...