0
任何想法如何我可以將正確的參數傳遞給xpath?必須有一些關於如何使用單/雙引號的內容。當我使用可變報價(紅寶石)
parser_xpath_identificator = "'//table/tbody[@id=\"threadbits_forum_251\"]/tr'"
給了我一個不正確的值或
parser_xpath_identificator = "'//table/tbody[@id="threadbits_forum_251"]/tr'"
給我一個錯誤語法錯誤,意想不到的tIDENTIFIER,期待$結束
require 'rubygems'
require 'mechanize'
parser_xpath_identificator = "'//table/tbody[@id=\"threadbits_forum_251\"]/tr'"
# parser_xpath_identificator = "'//table/tbody[@id="threadbits_forum_251"]/tr'"
#gives an error: syntax error, unexpected tIDENTIFIER, expecting $end
agent = WWW::Mechanize.new
page = agent.get("http://www.vbulletin.org/forum/index.php")
page = page.link_with(:text=>'vB4 General Discussions').click
puts "Page title: #{page.title}"
puts "\nfrom variable: #{page.parser.xpath(parser_xpath_identificator).length}"
puts "directly: #{page.parser.xpath('//table/tbody[@id="threadbits_forum_251"]/tr').length}"
@Jordan:謝謝你的正確答案和你的評論。現在我可以看到,第一個「雙引號根本就沒有必要......」 – Radek 2010-01-27 03:14:50