Question

une idée comment je peux passer l'argument correct XPath? Il doit y avoir quelque chose sur l'utilisation de simples / doubles guillemets. Lorsque j'utilise la variable

parser_xpath_identificator = "'//table/tbody[@id=\"threadbits_forum_251\"]/tr'" me donne une valeur incorrecte ou

parser_xpath_identificator = "'//table/tbody[@id="threadbits_forum_251"]/tr'" me donne une erreur erreur de syntaxe, tIDENTIFIER inattendue, attendant la fin $

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}"
Était-ce utile?

La solution

Dans les deux cas, vous nicher directement à l'intérieur de guillemets simples guillemets doubles, que je ne pense pas est correct. Essayez ceci:

parser_xpath_identificator = '//table/tbody[@id="threadbits_forum_251"]/tr'
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top