W
Wang Jian
[Note: parts of this message were removed to make it a legal post.]
## I wanted to work on something like the following example string
require 'hpricot'
string = '<html><a></a><a href="/123/456" title="2009-04-06">posted on April
2009</a></html>'
h = Hpricot(string)
t = "2009-04-06"
## Here it goes: confusion No.1
h.at('a[@title*="2009-04-06"]')
##=> returns the 2nd anchor element, as expected.
h.at('a[@title*=Time.now.strftime("%Y-%m-%d")]')
##=> *1st anchor element. Why is that??*
h.at("a[@title*=#{t}]")
##=> 2nd anchor. works fine
h.at('a[@title*="#{t}"]')
##=> *nil. Because of the single quote?*
## And here comes another confusion:
year = "2009"
h.at("a[@title*=#{t}][text()*='2009']")
##=> 2nd anchor, as expected.
h.at("a[@title*=#{t}][text()*=#{year}]")
##=> *nil. Why is that? Hpricot can't handle #{} more than once?*
## Hope you can fill me in on this one. Thanks!!
##Jay
## I wanted to work on something like the following example string
require 'hpricot'
string = '<html><a></a><a href="/123/456" title="2009-04-06">posted on April
2009</a></html>'
h = Hpricot(string)
t = "2009-04-06"
## Here it goes: confusion No.1
h.at('a[@title*="2009-04-06"]')
##=> returns the 2nd anchor element, as expected.
h.at('a[@title*=Time.now.strftime("%Y-%m-%d")]')
##=> *1st anchor element. Why is that??*
h.at("a[@title*=#{t}]")
##=> 2nd anchor. works fine
h.at('a[@title*="#{t}"]')
##=> *nil. Because of the single quote?*
## And here comes another confusion:
year = "2009"
h.at("a[@title*=#{t}][text()*='2009']")
##=> 2nd anchor, as expected.
h.at("a[@title*=#{t}][text()*=#{year}]")
##=> *nil. Why is that? Hpricot can't handle #{} more than once?*
## Hope you can fill me in on this one. Thanks!!
##Jay