简体   繁体   中英

How can I identify the language on a specific text using Selenium Webdriver

I'm new at this (only a week) and i've searched all over the net for this one. I need to get the text and then identify the language that's written on, like in this case 'portuguese'.

This is the div within the html I'm given:

<div class="episode-toggle" style="display: none;">
<div class="formattedTime">Hora de início/fim:  02:05 &nbsp;-&nbsp; 03:00 </div>
<div class="parental rating_R-10">Classificação Indicativa: 10<span class="path1"></span><span class="path2"></span></div>
<div>Sinopse: Playlist MTV é uma seleção com os melhores clipes 
relacionados a um estilo musical específico. Acompanhe agora a melhor 
seleção de clipes da música Pop.</div>
<div class="origin">País de origem: United States</div>
<div class="prodYear">Ano de produção: 2017</div></div>

This is what's on my selenium/java project:

    WebDriver driver = new ChromeDriver();
    driver.get("http://www.mtv.com.br/horarios");
    myString = driver.findElement(By.xpath("//div[@class='episode-toggle']")).getText();
    System.out.println(myString);}

Any idea how can I do it (if there's any way) be it with selenium or other software?

Thanks!

Try Google Cloud Translation API. https://cloud.google.com/translate/docs/?csw=1

They have samples in Java to give you a start.

Im a python person and the sample has method detect_language which i think should suffice your requirements https://github.com/GoogleCloudPlatform/python-docs-samples/blob/master/translate/cloud-client/snippets.py

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