问题描述
我正在使用Watir填写一个带有另一个程序的html代码的text_field。
网站内容的语言我正在转学是德语,所以有一些特殊的字符,不在英文字母表中。
这些字符在html文件中正确显示,但是当转移到Joomla安装的text_field(我正在使用该程序将网站转移到Joomla)时,特殊字符不能正常显示。
一个用户的结果很好的帮助,我已经能够解决一个以前的问题,现在通过以下方法传输内容:
browser.text_field(:id =>text)value =(open('my-site.html'){| f | f.read})
pre>
结果是,特殊字符显示如下:
über=> ³ber
vergißt=> vergi▀t
wählen=> wõhlen
geförderter=> gef÷rderter
用户猜测它与我所在的代码页有关,编码问题。运行DOS:chcp导致输出为850。
他试图解决问题的方法如下:
<$ value =(
Iconv.iconv('CP850','ISO- 8859-1',open('my-site.html'){| f | f.read})
)
不幸的是,这没有解决问题,特殊字符现在显示为:
\x81ber =über
vergi\xE1t =vergißt
和新行显示为\\\
我使用以下代码,使用以下代码,使用Mechanize刮下页面:
auszug = page.search('/ html / body / table / tr / td / table / tr [2] / td / table / tr / td [4]')
outputFile<< auszug
我希望你能帮助我,因为我只是在这里工作的志愿者有一点编程经验。如果我没有在下周运行这个程序(这个编码的东西是唯一真正阻止我的),那么我必须使用copy + paste手动传输一百页:/
感谢您花时间和您所投入的一切努力! : - )
Sebastian
你尝试转换为UTF -8?
browser.test_field(:id =>text)。value =(Iconv.conv -8','CP850',open('my-site.html'){| f | f.read})
I'm using Watir to fill out a text_field with the html-code that I have scraped with another program before.
The language of the website-content that I'm transfering is German, so there are some special characters involved, that don't exist in the English alphabet.
Those characters are displayed properly in the html-file, but when transfered into the text_field of the Joomla installation (I'm transfering a website to Joomla with this program), the special characters are not displayed properly.
As the result of a users great help, I have been able to solve a previous problem and am now transfering the content with the following method:
browser.text_field(:id => "text").value=(open('my-site.html') { |f| f.read })
The result was, that the special characters were shown as follows:
über => ³ber
vergißt => vergi▀t
wählen => wõhlen
geförderter => gef÷rderter
The user guessed that it had something to do with the codepage that I'm on and encoding issues. Running DOS: chcp resulted in the output of 850.
His attempt to solve the problem was the following:
require 'iconv'
browser.text_field(:id => "text").value=(
Iconv.iconv('CP850', 'ISO-8859-1', open('my-site.html') { |f| f.read })
)
Unfortunately, this didn't solve the problem and the special characters are now shown for example as: \x81ber = über vergi\xE1t = vergißtand new lines are shown as \n
I scraped the pages with the Mechanize, using the following code:
auszug=page.search ('/html/body/table/tr/td/table/tr[2]/td/table/tr/td[4]')
outputFile<<auszug
I hope you can somehow help me, as I'm just a volunteer working here with a bit of programming experience. If I don't get this program running by next week (this encoding thing is the only thing that's really stopping me), then I'll have to manually transfer a hundred pages using copy+paste :/
Thanks for taking the time and all the effort you're putting into this! :-)
Sebastian
Did you try converting to UTF-8?
browser.test_field(:id => "text").value=(Iconv.conv(‘utf-8’, 'CP850', open('my-site.html') {|f| f.read})
这篇关于在Ruby中使用Watir填充text_field时,编码问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!