我正在用ruby寫這個bot,遇到了麻煩,這顯示出來比我想象的要複雜得多。我讀了很多類似的文章,但沒有什麼幫助。Watir不兼容的字符編碼
它可能與watir無關,但只是爲了具體我說的是。另外,我在Fedora上。這是我的嘗試:
table = browser.table(:index , 7)
puts table[1][1].text
HTML表格片段是這樣的:
<table>
<tr>
something...
</tr>
<tr>
<td/>
<td>
Likiškėlių
</td>
</tr>
</table>
我得到
/usr/local/share/gems/gems/multi_json-1.7.2/lib/multi_json/vendor/okjson.rb:364:in `[]=': incompatible character encodings: UTF-8 and ASCII-8BIT (Encoding::CompatibilityError)
from /usr/local/share/gems/gems/multi_json-1.7.2/lib/multi_json/vendor/okjson.rb:364:in `unquote'
from /usr/local/share/gems/gems/multi_json-1.7.2/lib/multi_json/vendor/okjson.rb:288:in `strtok'
from /usr/local/share/gems/gems/multi_json-1.7.2/lib/multi_json/vendor/okjson.rb:254:in `tok'
from /usr/local/share/gems/gems/multi_json-1.7.2/lib/multi_json/vendor/okjson.rb:217:in `lex'
from /usr/local/share/gems/gems/multi_json-1.7.2/lib/multi_json/vendor/okjson.rb:45:in `decode'
from /usr/local/share/gems/gems/multi_json-1.7.2/lib/multi_json/adapters/ok_json.rb:13:in `load'
from /usr/local/share/gems/gems/multi_json-1.7.2/lib/multi_json/adapter.rb:19:in `load'
from /usr/local/share/gems/gems/multi_json-1.7.2/lib/multi_json.rb:120:in `load'
from /usr/local/share/gems/gems/selenium-webdriver-2.32.1/lib/selenium/webdriver/common/json_helper.rb:11:in `json_load'
from /usr/local/share/gems/gems/selenium-webdriver-2.32.1/lib/selenium/webdriver/remote/http/common.rb:59:in `create_response'
from /usr/local/share/gems/gems/selenium-webdriver-2.32.1/lib/selenium/webdriver/remote/http/default.rb:66:in `request'
from /usr/local/share/gems/gems/selenium-webdriver-2.32.1/lib/selenium/webdriver/remote/http/common.rb:40:in `call'
from /usr/local/share/gems/gems/selenium-webdriver-2.32.1/lib/selenium/webdriver/remote/bridge.rb:619:in `raw_execute'
from /usr/local/share/gems/gems/selenium-webdriver-2.32.1/lib/selenium/webdriver/remote/bridge.rb:597:in `execute'
from /usr/local/share/gems/gems/selenium-webdriver-2.32.1/lib/selenium/webdriver/remote/bridge.rb:508:in `getElementText'
from /usr/local/share/gems/gems/selenium-webdriver-2.32.1/lib/selenium/webdriver/common/element.rb:108:in `text'
from /usr/local/share/gems/gems/watir-webdriver-0.6.4/lib/watir-webdriver/elements/element.rb:86:in `text'
from watir.rb:25:in `<main>'
我也嘗試:
.gsub!(/\P{ASCII}/, '')
.delete!("^\u{0000}-\u{007F}")
變化,但它沒有解決。請幫忙!爲什麼編碼如此複雜?我無能爲力。
編輯:實際上,如果有幫助,我不需要打印字符串,但只寫入文件,但錯誤是相同的。
和我的紅寶石版本是:紅寶石1.9.3p392(2013年2月22日修訂39386)[i386的Linux的]
編輯:我也試過:
# encoding: ASCII-8BIT
or
# encoding: utf-8
with
puts table[1][1].text.length
仍然在同樣的錯誤
編輯因爲它甚至不會顯示.bytesize,我敢打賭它是watir。有什麼建議麼?