I can't get contains to work on a href

in Script development
Subscribe to I can't get contains to work on a href 6 posts, 3 voices



ekbworldwide Scriptwright
FirefoxWindows

I'm on an full page ad I want to skip - there's this link:

<a href="http://www.newsfactor.com/news/Panasonic--Best-Buy-To-Push-3-D-TV/story.xhtml?story_id=0200029Q08EG&full_skip=1"><!--b-->Go Directly to NewsFactor.com<!--/b--></a>

_____________________

// #1 using the text of the link
3-D-TV%2Fstory.xhtml%3Fstory_id%3D0200029Q08EG
var input = document.evaluate('//a[contains(.,"Go Directly to NewsFactor.com")]',document,null,XPathResult.FIRST_ORDERED_NODE_TYPE,null).singleNodeValue;
if (input) {
	location.href = input.href
}

Result - success.

_____________________

// #2 using the href
var input = document.evaluate('//a[@href[contains(.,"&full_skip=1")]]',document,null,XPathResult.FIRST_ORDERED_NODE_TYPE,null).singleNodeValue;
if (input) {
	location.href = input.href
}

Result - failure. Why doesn't it work?

 
Tim Smart Scriptwright
FirefoxMacintosh

Shouldn't it be this?:

var input = document.evaluate('//a[contains(@href,"&full_skip=1")]',
                              document,
                              null,
                              XPathResult.FIRST_ORDERED_NODE_TYPE,
                              null).
                     singleNodeValue;
if (input) {
    location.href = input.href
}
 
JoeSimmons Scriptwright
FirefoxWindows

ekbworldwide wrote:
contains(.,"&full_skip=1")
u checking the link text not @href

also remember, that & symbol might be &amp; but it shows up in firebug as &
ive tried to match hrefs by only using firebug, and i would use regex like /&something=(.*)/ but actually the & was &amp; so i had to use /(?:&|&amp;)something=(.*)/
 
ekbworldwide Scriptwright
FirefoxWindows

& and & - oops. Okay.

u checking the link text not @href
  • I still don't know how to check the href.
  • I also don't know how to use an regex after document.evaluate
  •  
    Tim Smart Scriptwright
    FirefoxMacintosh

    ekbworldwide wrote:
  • I still don't know how to check the href.
  • Have a look at my post above :p
    ekbworldwide wrote:
  • I also don't know how to use an regex after document.evaluate
  • You can't use Regexp inside a XPath expression, you can only loop over the resulting elements and compare things like .href and .textContent against a regexp

     
    ekbworldwide Scriptwright
    FirefoxWindows

    Have a look at my post above :p

    Oops, again. My mind is empty today - and not in the good zen-like way.

    Cross
    Presentational HTML allowed.
    Use <code> for inline code and <pre> for code blocks. Use &lt; and &gt; for literal < and >.
    We help break paragraphs and link your links.
    or cancel