I want to extract some information from this dynamic website with selenium and jsoup. To get the information I want to extract I have to click to the button "Details ?ffnen". The first picture shows the website before cklicking the button and the second shows the website after clicking the button. The red marked information is the information I want to extract.
I first tried to extract the information only with Jsoup, but as I was told Jsoup can not handle dynamic content, so I am now trying to extract the Information with selenium and Jsoup like you can see in the sourcecode. Howerver I am not really sure if selenium is the right thing for this, so maybe there are other ways to extract the information I need more simple, but it is important that this could be done with Java.
The next two pictures show the html code before clicking the button and after clicking the button.
public static void main(String[] args) {
WebDriver driver = new FirefoxDriver(createFirefoxProfile());
driver.get("http://www.seminarbewertung.de/seminar-bewertungen?id=3448");
//driver.findElement(By.cssSelector("input[type='button'][value='Details ?ffnen']")).click();
WebElement webElement = driver.findElement(By.cssSelector("input[type='submit'][value='Details ?ffnen'][rating_id='2318']"));
JavascriptExecutor executor = (JavascriptExecutor)driver;
executor.executeScript("arguments[0].click();", webElement);
String html_content = driver.getPageSource();
//driver.close();
Document doc1 = Jsoup.parse(html_content);
System.out.println("Hallo");
Elements elements = doc1.getAllElements();
for (Element element : elements) {
System.out.println(element);
}
}
private static FirefoxProfile createFirefoxProfile() {
File profileDir = new File("/tmp/firefox-profile-dir");
if (profileDir.exists())
return new FirefoxProfile(profileDir);
FirefoxProfile firefoxProfile = new FirefoxProfile();
File dir = firefoxProfile.layoutOnDisk();
try {
profileDir.mkdirs();
FileUtils.copyDirectory(dir, profileDir);
} catch (IOException e) {
e.printStackTrace();
}
return firefoxProfile;
}
With this source code I can not find the div element with the information I want to extract.
It would be really great, if somebody could help me with this.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…