简体   繁体   English

如何使用Selenium Webdriver识别特定文本上的语言

[英]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: 这是我得到的html中的div:

<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: 这是我的selenium / java项目中的内容:

    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. 试用Google Cloud Translation API。 https://cloud.google.com/translate/docs/?csw=1 https://cloud.google.com/translate/docs/?csw=1

They have samples in Java to give you a start. 他们有Java示例,可以帮助您入门。

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 我是一个python人员,该示例具有方法detect_language,我认为它可以满足您的要求https://github.com/GoogleCloudPlatform/python-docs-samples/blob/master/translate/cloud-client/snippets.py

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何验证特定文本下的文本 <DIV> 使用Selenium WebDriver(java)和Chrome浏览器标记? - How can I verify presence of text under a specific <DIV> tag using Selenium WebDriver (java) and Chrome? 如何使用 Selenium WebDriver 和 Java 关闭特定的 window? - How can I close a specific window using Selenium WebDriver with Java? 如何在TestNG中使用Selenium Webdriver使用text属性标识元素 - How to identify Elements using text attribute by Selenium Webdriver in TestNG 使用Selenium IE webdriver和JAVA识别特定字符串之后的文本 - Identify the text following a specific string with Selenium IE webdriver and JAVA 如何使用Selenium WebDriver配置网页语言 - How to configure webpage language using selenium webdriver 如何使用selenium webdriver从一个文档中选择文本 - How can i select text from one document using selenium webdriver 如何使用Selenium Webdriver从“ span”标签获取文本? - How can I get text from a “span” tag using Selenium Webdriver? 如何使用Selenium WebDriver从变量中提取文本? - How can I extract the text from a variable with Selenium WebDriver? 如何使用Java和Selenium2 / Webdriver将明天的日期输入文本字段 - How can I enter tomorrow's date into a text field using Java and Selenium2/Webdriver 如何在 Selenium WebDriver 中获取元素的文本? - How can I get text of an element in Selenium WebDriver?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM