开发者

quotes issue (ruby)

开发者 https://www.devze.com 2022-12-18 00:21 出处:网络
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

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

精彩评论

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