<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>网络编程</title>
	<atom:link href="http://www.sdgz.cn/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.sdgz.cn</link>
	<description>PHP RUBY</description>
	<lastBuildDate>Tue, 06 Jul 2010 21:50:17 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>ruby内嵌表达式</title>
		<link>http://www.sdgz.cn/ruby-embedded-expression/</link>
		<comments>http://www.sdgz.cn/ruby-embedded-expression/#comments</comments>
		<pubDate>Tue, 06 Jul 2010 21:50:17 +0000</pubDate>
		<dc:creator></dc:creator>
				<category><![CDATA[ruby]]></category>
		<category><![CDATA[内嵌表达式]]></category>

		<guid isPermaLink="false">http://www.sdgz.cn/?p=263</guid>
		<description><![CDATA[可以用#{}内嵌表达式，如：

ruby&#62; var = &#8220; abc &#8221;
&#8220; abc &#8221;
ruby&#62; &#8220;1234#{var}5678&#8243;
&#8220;1234 abc 5678&#8243;

]]></description>
			<content:encoded><![CDATA[<p>可以用#{}内嵌表达式，如：</p>
<ol>
<li>ruby<strong><span style="color: #006699;">&gt;</span></strong> <span style="color: #ff0000;">var</span> = <span style="color: #0000ff;">&#8220; abc &#8221;</span></li>
<li>&#8220; abc &#8221;</li>
<li>ruby<strong><span style="color: #006699;">&gt;</span></strong> &#8220;1234#{var}5678&#8243;</li>
<li>&#8220;1234 abc 5678&#8243;</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://www.sdgz.cn/ruby-embedded-expression/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>在Watir中利用AutoIt关闭弹窗</title>
		<link>http://www.sdgz.cn/the-watir-closed-shells-using-autoit-window/</link>
		<comments>http://www.sdgz.cn/the-watir-closed-shells-using-autoit-window/#comments</comments>
		<pubDate>Thu, 14 Jan 2010 14:14:31 +0000</pubDate>
		<dc:creator>leleba</dc:creator>
				<category><![CDATA[watir]]></category>
		<category><![CDATA[autoit]]></category>
		<category><![CDATA[popup]]></category>
		<category><![CDATA[弹窗]]></category>

		<guid isPermaLink="false">http://www.sdgz.cn/the-watir-closed-shells-using-autoit-window/</guid>
		<description><![CDATA[
今天是一个高兴的日子，我终于成功地利用AutoIt关闭IE弹窗了。
利用Watir进行网页测试已经有2年多了，但始终在处理IE弹窗上卡壳，网上有不少介绍和例子可供借鉴，但以前均未能测试成功。
先将代码列出：
require &#8216;watir&#8217;
require &#8216;win32ole&#8217;
require &#8216;watir/windowhelper&#8217;
&#8230;&#8230;&#8230;
&#8230;&#8230;&#8230;
ie33.link(:id, &#8220;something&#8221;).click_no_wait
sleep 3 #时间长短可能影响能否关闭弹窗
#sleep 2
puts &#8220;before autoit&#8221;
autoit = WIN32OLE.new(&#8216;AutoItX3.Control&#8217;)
puts &#8220;before loop do&#8221;
    loop do
      puts &#8220;in loop&#8221;
      #ret = autoit.WinWaitActive(&#8220;Windows Internet Explorer&#8221;, &#8220;&#8221;,9)
      #ret = autoit.WinWaitActive(&#8220;来自网页的信息&#8221;, &#8220;&#8221;,9)
      ret = autoit.WinWaitActive(&#8220;Microsoft Internet Explorer&#8221;, &#8220;&#8221;,9)
      puts &#8220;after ret&#8221;
      puts(ret) 
      if (ret==1)
      autoit.Send(&#8220;{Enter}&#8221;)
      exit
      end
      sleep 3
    end
以前不成功的原因，主要是测试用电脑的环境不一样，今天尝试以上代码时，刚开始也不成功，ret始终等于0,偶然用鼠标碰了一下IE窗口，ret变为1。这才发现ie33.link(:id, &#8220;something&#8221;).click_no_wait语句之后的sleep时间长短很关键，不同的电脑以及网络速度不同，sleep时间不匹配的话，以上代码不能正常运行。
比较疑惑的是，以下代码不行：
require &#8216;watir&#8217;
require &#8216;win32ole&#8217;
require &#8216;watir/windowhelper&#8217;
&#8230;&#8230;&#8230;
&#8230;&#8230;&#8230;
Thread.new{
puts &#8220;before autoit&#8221;
autoit = WIN32OLE.new(&#8216;AutoItX3.Control&#8217;)
puts &#8220;before loop do&#8221;
    loop [...]]]></description>
			<content:encoded><![CDATA[<div id="PublishedByWebStory-[5]1_605B6096DCCC4E51B10A013A9BCBFAC0_C3BDA40C79D04852B94909383ACE15CB">
<p>今天是一个高兴的日子，我终于成功地利用AutoIt关闭IE弹窗了。</p>
<p>利用Watir进行网页测试已经有2年多了，但始终在处理IE弹窗上卡壳，网上有不少介绍和例子可供借鉴，但以前均未能测试成功。</p>
<p>先将代码列出：</p>
<p>require &#8216;watir&#8217;<br />
require &#8216;win32ole&#8217;<br />
require &#8216;watir/windowhelper&#8217;</p>
<p>&#8230;&#8230;&#8230;</p>
<p>&#8230;&#8230;&#8230;</p>
<p>ie33.link(:id, &#8220;something&#8221;).click_no_wait<br />
sleep 3 #时间长短可能影响能否关闭弹窗</p>
<p>#sleep 2<br />
puts &#8220;before autoit&#8221;<br />
autoit = WIN32OLE.new(&#8216;AutoItX3.Control&#8217;)<br />
puts &#8220;before loop do&#8221;<br />
    loop do<br />
      puts &#8220;in loop&#8221;<br />
      #ret = autoit.WinWaitActive(&#8220;Windows Internet Explorer&#8221;, &#8220;&#8221;,9)<br />
      #ret = autoit.WinWaitActive(&#8220;来自网页的信息&#8221;, &#8220;&#8221;,9)<br />
      ret = autoit.WinWaitActive(&#8220;Microsoft Internet Explorer&#8221;, &#8220;&#8221;,9)</p>
<p>      puts &#8220;after ret&#8221;<br />
      puts(ret) </p>
<p>      if (ret==1)<br />
      autoit.Send(&#8220;{Enter}&#8221;)<br />
      exit<br />
      end<br />
      sleep 3<br />
    end</p>
<p>以前不成功的原因，主要是测试用电脑的环境不一样，今天尝试以上代码时，刚开始也不成功，ret始终等于0,偶然用鼠标碰了一下IE窗口，ret变为1。这才发现ie33.link(:id, &#8220;something&#8221;).click_no_wait语句之后的sleep时间长短很关键，不同的电脑以及网络速度不同，sleep时间不匹配的话，以上代码不能正常运行。</p>
<p>比较疑惑的是，以下代码不行：</p>
<p>require &#8216;watir&#8217;<br />
require &#8216;win32ole&#8217;<br />
require &#8216;watir/windowhelper&#8217;</p>
<p>&#8230;&#8230;&#8230;</p>
<p>&#8230;&#8230;&#8230;</p>
<p>Thread.new{</p>
<p>puts &#8220;before autoit&#8221;<br />
autoit = WIN32OLE.new(&#8216;AutoItX3.Control&#8217;)<br />
puts &#8220;before loop do&#8221;<br />
    loop do<br />
      puts &#8220;in loop&#8221;<br />
      #ret = autoit.WinWaitActive(&#8220;Windows Internet Explorer&#8221;, &#8220;&#8221;,9)<br />
      #ret = autoit.WinWaitActive(&#8220;来自网页的信息&#8221;, &#8220;&#8221;,9)<br />
      ret = autoit.WinWaitActive(&#8220;Microsoft Internet Explorer&#8221;, &#8220;&#8221;,9)</p>
<p>      puts &#8220;after ret&#8221;<br />
      puts(ret) </p>
<p>      if (ret==1)<br />
      autoit.Send(&#8220;{Enter}&#8221;)<br />
      exit<br />
      end<br />
      sleep 3<br />
    end</p>
<p>}</p>
<p>ie33.link(:id, &#8220;something&#8221;).click_no_wait</p>
<p>在将ie33.link(:id, &#8220;something&#8221;).click_no_wait修改为ie33.link(:id, &#8220;something&#8221;).click之后，以上代码运行成功。</p>
<p>第一次往往是最难的，以后通过watir + nobogiri +mechanize + autoit, 基本上可以解决大部分网页测试的问题了。</p></div>
<p><a href="http://www.sdgz.cn">我自己的原创: http://www.sdgz.cn</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.sdgz.cn/the-watir-closed-shells-using-autoit-window/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>watir中获得IE进程号的语句</title>
		<link>http://www.sdgz.cn/watir-to-get-ie-process-id-of-the-statement/</link>
		<comments>http://www.sdgz.cn/watir-to-get-ie-process-id-of-the-statement/#comments</comments>
		<pubDate>Wed, 13 Jan 2010 13:33:15 +0000</pubDate>
		<dc:creator>leleba</dc:creator>
				<category><![CDATA[watir]]></category>

		<guid isPermaLink="false">http://www.sdgz.cn/watir-to-get-ie-process-id-of-the-statement/</guid>
		<description><![CDATA[watir中获得IE进程号的语句：
ie33 = Watir::IE.start(&#8220;http://www.google.com&#8220;)
pid_number = Watir::IE::Process.process_id_from_hwnd(ie33.hwnd)
本文原创于: http://www.sdgz.cn
]]></description>
			<content:encoded><![CDATA[<p>watir中获得IE进程号的语句：</p>
<p>ie33 = Watir::IE.start(&#8220;<a href="http://www.google.com">http://www.google.com</a>&#8220;)</p>
<p>pid_number = Watir::IE::Process.process_id_from_hwnd(ie33.hwnd)</p>
<p>本文原创于: http://www.sdgz.cn</p>
]]></content:encoded>
			<wfw:commentRss>http://www.sdgz.cn/watir-to-get-ie-process-id-of-the-statement/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>TOP5外包网站</title>
		<link>http://www.sdgz.cn/top5-outsourcing-website/</link>
		<comments>http://www.sdgz.cn/top5-outsourcing-website/#comments</comments>
		<pubDate>Thu, 07 Jan 2010 10:07:30 +0000</pubDate>
		<dc:creator>leleba</dc:creator>
				<category><![CDATA[PHP学习]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[watir]]></category>
		<category><![CDATA[elance guru rentacoder getafreelancer scriptlance]]></category>

		<guid isPermaLink="false">http://www.sdgz.cn/top5-outsourcing-website/</guid>
		<description><![CDATA[1. eLance http://www.elance.com/
2. Guru http://www.guru.com/
3. RentACoder http://www.rentacoder.com/
4. GetAFreelancer http://www.getafreelancer.com/
5. ScriptLance http://www.scriptlance.com/

]]></description>
			<content:encoded><![CDATA[<p><span style="TEXT-DECORATION: underline"><span style="COLOR: #0000ff">1. eLance <br/><a href="http://www.elance.com/">http://www.elance.com/</a></span></span></p>
<p><span style="TEXT-DECORATION: underline"><span style="COLOR: #0000ff">2. Guru <br/><a href="http://www.guru.com/">http://www.guru.com/</a></span></span></p>
<p><span style="TEXT-DECORATION: underline"><br/>3. RentACoder <br/><a href="http://www.rentacoder.com/">http://www.rentacoder.com/</a></span></p>
<p><br/>4. GetAFreelancer <br/><a href="http://www.getafreelancer.com/">http://www.getafreelancer.com/</a></p>
<p>5. ScriptLance <br/><a href="http://www.scriptlance.com/">http://www.scriptlance.com/</a></p>
<p/>
]]></content:encoded>
			<wfw:commentRss>http://www.sdgz.cn/top5-outsourcing-website/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>watir中统计网页中链接数量的语句</title>
		<link>http://www.sdgz.cn/watir-number-of-statistical-links-page-statement/</link>
		<comments>http://www.sdgz.cn/watir-number-of-statistical-links-page-statement/#comments</comments>
		<pubDate>Thu, 07 Jan 2010 09:25:06 +0000</pubDate>
		<dc:creator>leleba</dc:creator>
				<category><![CDATA[watir]]></category>
		<category><![CDATA[网页元素数量]]></category>

		<guid isPermaLink="false">http://www.sdgz.cn/watir-number-of-statistical-links-page-statement/</guid>
		<description><![CDATA[有时候需要统计网页中或者网页某个区域中的链接数量，刚开始我尝试以下语句，但不成功： ie.links(:id, /bra bra/).length
后来发现以下语句可行： ie.div(:id, &#8220;searchList&#8221;).links
之后发现如下更好的语句：
links_searchlist = ie101.links.find_all { &#124;link&#124; link.class_name == &#8216;permalink&#8217; } puts &#8220;the links in the searchlist:&#8221; puts links_searchlist.length
          searchlistlinks = ie102.links.find_all { &#124;link&#124; link.id =~ /hitURL/ } links_searchlist = searchlistlinks.length puts links_searchlist
searchlistlinks = ie33.links.find_all { &#124;link&#124; link.href =~ /something/ } 类似的语句不行：searchlistlinks = [...]]]></description>
			<content:encoded><![CDATA[<p>有时候需要统计网页中或者网页某个区域中的链接数量，刚开始我尝试以下语句，但不成功： <br/>ie.links(:id, /bra bra/).length</p>
<p>后来发现以下语句可行： <br/>ie.div(:id, &#8220;searchList&#8221;).links</p>
<p>之后发现如下更好的语句：</p>
<p>links_searchlist = ie101.links.find_all { |link| link.class_name == &#8216;permalink&#8217; } <br/>puts &#8220;the links in the searchlist:&#8221; <br/>puts links_searchlist.length</p>
<p>          <br/>searchlistlinks = ie102.links.find_all { |link| link.id =~ /hitURL/ } <br/>links_searchlist = searchlistlinks.length <br/>puts links_searchlist</p>
<p>searchlistlinks = ie33.links.find_all { |link| link.href =~ /something/ } <br/>类似的语句不行：searchlistlinks = ie33.links.find_all { |link| link.url =~ /something/ }</p>
<p>最近发现，如果链接数量比较多，以上语句耗时太长，通过google和百度，找到了更高效的语句：</p>
<p>links = ie51.div(:id, &#8216;threadlist&#8217;).html.scan(/something/).count <br/>puts links</p>
]]></content:encoded>
			<wfw:commentRss>http://www.sdgz.cn/watir-number-of-statistical-links-page-statement/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>firewatir 1.6.5不支持中文字符</title>
		<link>http://www.sdgz.cn/firewatir-1-6-5-does-not-support-chinese-characters/</link>
		<comments>http://www.sdgz.cn/firewatir-1-6-5-does-not-support-chinese-characters/#comments</comments>
		<pubDate>Thu, 07 Jan 2010 09:12:48 +0000</pubDate>
		<dc:creator>leleba</dc:creator>
				<category><![CDATA[watir]]></category>
		<category><![CDATA[中文字符]]></category>

		<guid isPermaLink="false">http://www.sdgz.cn/firewatir-1-6-5-does-not-support-chinese-characters/</guid>
		<description><![CDATA[想了很多办法，包括更改.rb文件和firefox浏览器的编码，都不能用firewatir 1.6.5往网页上输入中文字符，测试的代码如下：
require &#8216;rubygems&#8217;
require &#8216;firewatir&#8217;
ff = FireWatir::Firefox.new
ff.goto &#8220;http://www.google.com&#8221;
sleep 1
ff.text_field(:name, &#8216;q&#8217;).set(&#8216;电&#8217;)
我还利用了以下语句，同样没有效果：
g_word = &#8216;电&#8217;
puts g_word
g_word_gb = Iconv.iconv(&#8220;GB2312//IGNORE&#8221;,&#8221;UTF-8//IGNORE&#8221;,g_word)
puts g_word_gb
sleep 1
ff.text_field(:name, &#8216;q&#8217;).set(g_word_gb[0])
或者：
g_word = &#8216;电&#8217;
puts g_word
g_word_utf = Iconv.iconv(&#8220;UTF-8//IGNORE&#8221;,&#8221;GB2312//IGNORE&#8221;,g_word)
puts g_word_utf
sleep 1
ff.text_field(:name, &#8216;q&#8217;).set(g_word_utf[0])

对于Watir 1.6.5, 将\Ruby\lib\ruby\gems\1.8\gems\watir-1.6.5\lib\watir\win32ole.rb文件中的语句　WIN32OLE.codepage = WIN32OLE::CP_UTF8　替换成　WIN32OLE.codepage = WIN32OLE::CP_ACP，即可让watir支持中文字符。
]]></description>
			<content:encoded><![CDATA[<p>想了很多办法，包括更改.rb文件和firefox浏览器的编码，都不能用firewatir 1.6.5往网页上输入中文字符，测试的代码如下：</p>
<p>require &#8216;rubygems&#8217;<br />
require &#8216;firewatir&#8217;</p>
<p>ff = FireWatir::Firefox.new<br />
ff.goto &#8220;<a href="http://www.google.com/">http://www.google.com</a>&#8221;</p>
<p>sleep 1<br />
ff.text_field(:name, &#8216;q&#8217;).set(&#8216;电&#8217;)</p>
<p>我还利用了以下语句，同样没有效果：</p>
<p>g_word = &#8216;电&#8217;<br />
puts g_word<br />
g_word_gb = Iconv.iconv(&#8220;GB2312//IGNORE&#8221;,&#8221;UTF-8//IGNORE&#8221;,g_word)<br />
puts g_word_gb</p>
<p>sleep 1<br />
ff.text_field(:name, &#8216;q&#8217;).set(g_word_gb[0])</p>
<p>或者：</p>
<p>g_word = &#8216;电&#8217;<br />
puts g_word<br />
g_word_utf = Iconv.iconv(&#8220;UTF-8//IGNORE&#8221;,&#8221;GB2312//IGNORE&#8221;,g_word)<br />
puts g_word_utf</p>
<p>sleep 1<br />
ff.text_field(:name, &#8216;q&#8217;).set(g_word_utf[0])</p>
<p><span id="more-258"></span></p>
<p>对于Watir 1.6.5, 将\Ruby\lib\ruby\gems\1.8\gems\watir-1.6.5\lib\watir\win32ole.rb文件中的语句　WIN32OLE.codepage = WIN32OLE::CP_UTF8　替换成　WIN32OLE.codepage = WIN32OLE::CP_ACP，即可让watir支持中文字符。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.sdgz.cn/firewatir-1-6-5-does-not-support-chinese-characters/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>检查watir和firewatir版本的方法</title>
		<link>http://www.sdgz.cn/check-watir-and-firewatir-version-of-the-method-of/</link>
		<comments>http://www.sdgz.cn/check-watir-and-firewatir-version-of-the-method-of/#comments</comments>
		<pubDate>Thu, 07 Jan 2010 08:17:36 +0000</pubDate>
		<dc:creator>leleba</dc:creator>
				<category><![CDATA[watir]]></category>
		<category><![CDATA[版本]]></category>

		<guid isPermaLink="false">http://www.sdgz.cn/check-watir-and-firewatir-version-of-the-method-of/</guid>
		<description><![CDATA[编辑一个rb文件并执行，可以获得watir和firewatir的版本信息，以下是相应的代码：
require &#8216;watir&#8217;
puts Watir::IE::VERSION
 
require &#8216;firewatir&#8217;
puts FireWatir::Firefox::VERSION
]]></description>
			<content:encoded><![CDATA[<p>编辑一个rb文件并执行，可以获得watir和firewatir的版本信息，以下是相应的代码：</p>
<p>require &#8216;watir&#8217;</p>
<p>puts Watir::IE::VERSION</p>
<p> <span id="more-257"></span>
<p>require &#8216;firewatir&#8217;</p>
<p>puts FireWatir::Firefox::VERSION</p>
]]></content:encoded>
			<wfw:commentRss>http://www.sdgz.cn/check-watir-and-firewatir-version-of-the-method-of/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ruby的url解码函数和url编码函数</title>
		<link>http://www.sdgz.cn/ruby-of-the-url-decoding-function-and-url-encoding-function/</link>
		<comments>http://www.sdgz.cn/ruby-of-the-url-decoding-function-and-url-encoding-function/#comments</comments>
		<pubDate>Tue, 05 Jan 2010 11:08:18 +0000</pubDate>
		<dc:creator>leleba</dc:creator>
				<category><![CDATA[ruby]]></category>
		<category><![CDATA[url解码　url编码]]></category>

		<guid isPermaLink="false">http://www.sdgz.cn/ruby-of-the-url-decoding-function-and-url-encoding-function/</guid>
		<description><![CDATA[含中文字符的url是一些乱码，如中文&#8221;个&#8221;，在url中表示为&#8221;％b8%f6&#8243;。有时需要进行url解码和编码，两个函数如下：
def URLDecode(str) str.gsub!(/%[a-fA-F0-9]{2}/) { &#124;x&#124; x = x[1..2].hex.chr } end def URLEncode(str) str.gsub!(/[^\w$&#38;\-+.,\/:;=?@]/) { &#124;x&#124; x = format(&#8220;%%%x&#8220;, x[0]) } end
]]></description>
			<content:encoded><![CDATA[<p>含中文字符的url是一些乱码，如中文&#8221;个&#8221;，在url中表示为&#8221;％b8%f6&#8243;。有时需要进行url解码和编码，两个函数如下：</p>
<p><span style="COLOR: green">def</span> <span style="COLOR: blue">URLDecode</span><span style="COLOR: olive">(</span><span style="COLOR: blue">str</span><span style="COLOR: olive">)</span><span style="COLOR: gray"><br/></span> <span style="COLOR: blue">str</span><span style="COLOR: gray">.</span><span style="COLOR: blue">gsub</span><span style="COLOR: gray">!</span><span style="COLOR: olive">(</span><span style="COLOR: #8b0000">/</span><span style="COLOR: red">%[a-fA-F0-9]{2}</span><span style="COLOR: #8b0000">/</span><span style="COLOR: olive">)</span> <span style="COLOR: gray">{ |</span><span style="COLOR: blue">x</span><span style="COLOR: gray">|</span> <span style="COLOR: blue">x</span> <span style="COLOR: gray">=</span> <span style="COLOR: blue">x</span><span style="COLOR: olive">[</span><span style="COLOR: maroon">1..2</span><span style="COLOR: olive">]</span><span style="COLOR: gray">.</span><span style="COLOR: blue">hex</span><span style="COLOR: gray">.</span><span style="COLOR: blue">chr</span> <span style="COLOR: gray">} <br/></span><span style="COLOR: green">end</span><span style="COLOR: gray"><br/><br/></span> <span style="COLOR: green">def</span> <span style="COLOR: blue">URLEncode</span><span style="COLOR: olive">(</span><span style="COLOR: blue">str</span><span style="COLOR: olive">)</span><span style="COLOR: gray"><br/></span> <span style="COLOR: blue">str</span><span style="COLOR: gray">.</span><span style="COLOR: blue">gsub</span><span style="COLOR: gray">!</span><span style="COLOR: olive">(</span><span style="COLOR: #8b0000">/</span><span style="COLOR: red">[^</span><span style="COLOR: navy">\w</span><span style="COLOR: red">$&amp;</span><span style="COLOR: navy">\-</span><span style="COLOR: red">+.,</span><span style="COLOR: navy">\/</span><span style="COLOR: red">:;=?@]</span><span style="COLOR: #8b0000">/</span><span style="COLOR: olive">)</span> <span style="COLOR: gray">{ |</span><span style="COLOR: blue">x</span><span style="COLOR: gray">|</span> <span style="COLOR: blue">x</span> <span style="COLOR: gray">=</span> <span style="COLOR: blue">format</span><span style="COLOR: olive">(</span><span style="COLOR: #8b0000">&#8220;</span><span style="COLOR: red">%%%x</span><span style="COLOR: #8b0000">&#8220;</span><span style="COLOR: gray">,</span> <span style="COLOR: blue">x</span><span style="COLOR: olive">[</span><span style="COLOR: maroon">0</span><span style="COLOR: olive">])</span> <span style="COLOR: gray">} <br/></span><span style="COLOR: green">end</span></p>
]]></content:encoded>
			<wfw:commentRss>http://www.sdgz.cn/ruby-of-the-url-decoding-function-and-url-encoding-function/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>给ruby程序以及ruby待操作的文件以完整的路径</title>
		<link>http://www.sdgz.cn/to-the-ruby-and-the-ruby-process-to-be-operated-with-the-full-path-to-the-file/</link>
		<comments>http://www.sdgz.cn/to-the-ruby-and-the-ruby-process-to-be-operated-with-the-full-path-to-the-file/#comments</comments>
		<pubDate>Wed, 30 Dec 2009 07:32:15 +0000</pubDate>
		<dc:creator>leleba</dc:creator>
				<category><![CDATA[ruby]]></category>
		<category><![CDATA[文件操作　路径]]></category>

		<guid isPermaLink="false">http://www.sdgz.cn/to-the-ruby-and-the-ruby-process-to-be-operated-with-the-full-path-to-the-file/</guid>
		<description><![CDATA[有的时候需要给ruby程序以及ruby待操作的文件以完整的路径，举例说明吧：
在g:\ding\anpc\163_anpc.rb程序中有如下代码：
3.times { load &#8216;..\anpc\data_163.rb&#8217; load &#8216;..\bin\bin_163.rb&#8217; }
如果在g:\ding\anpc\ 下执行163_anpc.rb,　程序可以正常运行，但如果在别的路径，比如c:\，执行g:\ding\anpc\163_anpc.rb，程序就会报错，说找不到data_163.rb和bin_163.rb。
解决问题的方法是给ruby程序以完整的路径，如下所示：
3.times { load File.join(File.dirname(__FILE__), &#8216;data_163.rb&#8217;) load File.join(File.dirname(__FILE__), &#8216;../bin/bin_163.rb&#8217;) }
类似的例子：
在g:\ding\anpc\data_163.rb程序中有如下代码：
#初始化user users = [] File.open(&#8216;user_163_anpc.txt&#8217;) do &#124;f&#124; f.each_line do &#124;line&#124; words = line.split(&#8216; &#8216;) users &#60;&#60; {:user =&#62; words[0], :password =&#62; words[1]} end end
该程序在g:\ding\anpc\ 下执行data_163.rb,　文件操作正常，但如果在别的路径，比如c:\，执行g:\ding\anpc\data_163.rb，程序就会报错，说找不到文件user_163_anpc.txt。
解决问题的方法是给待操作的文件以完整的路径，如下所示：
#初始化user users = [] users_filename = File.join(File.dirname(__FILE__), &#8216;user_sina_anpc.txt&#8217;) File.open(users_filename) do &#124;f&#124; f.each_line do &#124;line&#124; words = [...]]]></description>
			<content:encoded><![CDATA[<p>有的时候需要给ruby程序以及ruby待操作的文件以完整的路径，举例说明吧：</p>
<p>在g:\ding\anpc\163_anpc.rb程序中有如下代码：</p>
<p>3.times { <br/>load &#8216;..\anpc\data_163.rb&#8217; <br/>load &#8216;..\bin\bin_163.rb&#8217; <br/>}</p>
<p>如果在g:\ding\anpc\ 下执行163_anpc.rb,　程序可以正常运行，但如果在别的路径，比如c:\，执行g:\ding\anpc\163_anpc.rb，程序就会报错，说找不到data_163.rb和bin_163.rb。</p>
<p>解决问题的方法是给ruby程序以完整的路径，如下所示：</p>
<p>3.times { <br/>load File.join(File.dirname(__FILE__), &#8216;data_163.rb&#8217;) <br/>load File.join(File.dirname(__FILE__), &#8216;../bin/bin_163.rb&#8217;) <br/>}</p>
<p>类似的例子：</p>
<p>在g:\ding\anpc\data_163.rb程序中有如下代码：</p>
<p>#初始化user <br/>users = [] <br/>File.open(&#8216;user_163_anpc.txt&#8217;) do |f| <br/>f.each_line do |line| <br/>words = line.split(&#8216; &#8216;) <br/>users &lt;&lt; {:user =&gt; words[0], :password =&gt; words[1]} <br/>end <br/>end</p>
<p>该程序在g:\ding\anpc\ 下执行data_163.rb,　文件操作正常，但如果在别的路径，比如c:\，执行g:\ding\anpc\data_163.rb，程序就会报错，说找不到文件user_163_anpc.txt。</p>
<p>解决问题的方法是给待操作的文件以完整的路径，如下所示：</p>
<p>#初始化user <br/>users = [] <br/>users_filename = File.join(File.dirname(__FILE__), &#8216;user_sina_anpc.txt&#8217;) <br/>File.open(users_filename) do |f| <br/>f.each_line do |line| <br/>words = line.split(&#8216; &#8216;) <br/>users &lt;&lt; {:user =&gt; words[0], :password =&gt; words[1]} <br/>end <br/>end</p>
<p>本文原创于<a href="http://www.sdgz.cn"><span style="COLOR: #000000">：</span>http://www.sdgz.cn</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.sdgz.cn/to-the-ruby-and-the-ruby-process-to-be-operated-with-the-full-path-to-the-file/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>watir程序开头应包含require &#8216;rubygems&#8217;</title>
		<link>http://www.sdgz.cn/watir-program-should-begin-with-require-rubygems/</link>
		<comments>http://www.sdgz.cn/watir-program-should-begin-with-require-rubygems/#comments</comments>
		<pubDate>Mon, 28 Dec 2009 04:38:56 +0000</pubDate>
		<dc:creator>leleba</dc:creator>
				<category><![CDATA[watir]]></category>
		<category><![CDATA[rubygems]]></category>

		<guid isPermaLink="false">http://www.sdgz.cn/watir-program-should-begin-with-require-rubygems/</guid>
		<description><![CDATA[最近忽然感觉到在watir程序的开头，应包含require &#8216;rubygems&#8217;，否则某些情况下会发生比较奇怪的现象。
本文原创于：http://www.sdgz.cn        
]]></description>
			<content:encoded><![CDATA[<p>最近忽然感觉到在watir程序的开头，应包含require &#8216;rubygems&#8217;，否则某些情况下会发生比较奇怪的现象。</p>
<p>本文原创于：<a href="http://www.sdgz.cn">http://www.sdgz.cn</a>        </p>
]]></content:encoded>
			<wfw:commentRss>http://www.sdgz.cn/watir-program-should-begin-with-require-rubygems/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
