2017-05-14 44 views
0

我是新来的硒,我尝试几个网站进行测试。 遇到了泰米尔语和印地语字体被废弃为“??????”的情况无法抓取非英文字体 - 硒

我试图通过记事本++,sublimetext和excel打开输出,但仍显示为“??????”

Xpath tried - //h1//following::p[@id='topDescription'] 

Test URLs 
"https://www.hooq.tv/catalog/7a6d593d-e8f3-47b6-92ae-469b8e08178e?__sr=feed" 
"https://www.hooq.tv/catalog/d023630f-882b-4df4-8cb5-857ebfff20b4?__sr=feed" 

代码

d.get("https://www.hooq.tv/catalog/7a6d593d-e8f3-47b6-92ae-469b8e08178e?__sr=feed"); 
d.findElement(By.xpath("//h1//following::p[@id='topDescription']")).getText(); 

这是一些关于编码问题?

+0

如果将抓取的数据直接保存到支持该类内容的文件格式,那将会更好。 – kushal

回答

0

首先,请确保您在将文本保存到外部文件之前可以正确获取原始文本。

我测试了您的元素在java中的.getText(),它是按原样返回字符串。

enter image description here 接下来,您需要确保在文件写入期间,字符集编码是UTF-8。

下面是使用org.apache.commons.io.FileUtils样本:

FileUtils.write(new File("C:/temp/test.txt"), str, "UTF-8"); 
FileUtils.write(new File("C:/temp/test.csv"), str, "UTF-8"); 

enter image description here

希望它能帮助。