cuestión cotizaciones (rubí)
-
23-09-2019 - |
Pregunta
alguna idea de cómo puedo pasar argumento correcto XPath? Tiene que haber algo acerca de cómo usar comillas simples / dobles. Cuando utilizo la variable
parser_xpath_identificator = "'//table/tbody[@id=\"threadbits_forum_251\"]/tr'"
me da un valor incorrecto o
parser_xpath_identificator = "'//table/tbody[@id="threadbits_forum_251"]/tr'"
me da un error error de sintaxis, inesperada tIDENTIFIER, esperando $ 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}"
Solución
En ambos casos estás muy anidación comillas simples directamente dentro de las comillas dobles, que no creo que sea correcto. Prueba esto:
parser_xpath_identificator = '//table/tbody[@id="threadbits_forum_251"]/tr'
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow