开发者

quotes issue (ruby)

any idea how I can pass correct argument to xpath? There must be something about how to use single/double quotes. When I use variable

parser_xpath_identificator = "'//table/tbody[@id=\"threadbits_forum_251\"]/tr'" gives me an incorrect value or

parser_xpath_identificator = "'//table/tbody[@id="threadbits_forum_251"]/tr'" gives me an error syntax error, unexpected tIDENTIFIER, expecting $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开发者_JAVA百科="threadbits_forum_251"]/tr').length}"


In both cases you're nesting single-quotes directly inside double-quotes, which I don't think is correct. Try this:

parser_xpath_identificator = '//table/tbody[@id="threadbits_forum_251"]/tr'
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜