2017-05-14 49 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

希望它能幫助。