简体   繁体   中英

I cannot get text With jsoup : element.text()

I cannot get text With Jsoup : element.text()
It doesn't show me anything, someone help me please.

 org.jsoup.nodes.Document d = Jsoup.connect("https://translate.google.com/#en/ar/scraping").get();
 org.jsoup.nodes.Element element = d.getElementById("result_box");
 out.print(element.text());       

When you view the static page source here: https://translate.google.com/#en/ar/scraping you'll see that it contains this:

<span id="result_box" class="short_text"></span>

But on loading the page in your browser you'll see that element is changed to:

<span id="result_box" class="short_text" lang="ar">
    <span class="">...</span>
</span>

So, the content of the result_box span is populated dynamically.

This means that it cannot be scraped by JSoup.

To read dynamic content you'll need to use a webdriver such as Selenium .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM