知道如何将正确的参数传递给 xpath 吗?必须有一些关于如何使用单引号/双引号的东西。当我使用变量时
parser_xpath_identificator = "'//table/tbody[@id=\"threadbits_forum_251\"]/tr'"
给我一个不正确的值或
parser_xpath_identificator = "'//table/tbody[@id="threadbits_forum_251"]/tr'"
给我一个错误语法错误,意外的 tIDENTIFIER,期待 $end
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}"