title: Groovy XML parsing (HTML slurping), can't get my specific case to work
body: <p>Okay, here's what I'm looking for.</p>
  
  <p>I want to go into the DOM and look for an <code>&lt;a id&gt;</code> starting with "thread_title_". Here are a couple things I've tried:</p>
  
  <pre><code>// setup
  def slurper = new XmlSlurper(new org.ccil.cowan.tagsoup.Parser())
  def gurl = new URL("url")
  gurl.withReader { gReader -&gt;
  
    def try1 = gHTML.body.find { it['@id'].startsWith("thread_title_") }
    // fails: Caught: groovy.lang.MissingMethodException: No signature of method: groovy.util.slurpersupport.Attributes.startsWith() is applicable for argument types: (java.lang.String) values: [thread_title_]
  
    def try2 = gHTML.body.find { it['@id'] =~ /thread_title_/ }
    // fails: Caught: groovy.lang.MissingMethodException: No signature of method: groovy.util.slurpersupport.Attributes.startsWith() is applicable for argument types: (java.lang.String) values: [thread_title_]
  
    def try3 = gHTML.body.find { it['@id'].name.startsWith("thread_title_") }
    // fails: Caught: groovy.lang.MissingMethodException: No signature of method: groovy.util.slurpersupport.NodeChildren.startsWith() is applicable for argument types: (java.lang.String) values: [thread_title_]
  
    def try4 = gHTML.body.find { it['@id'] == 'thread_title_745429' }
    // doesn't fail, but doesn't return anything either
  
    def try5 = gHTML.body.findAll { it.name() == 'a' &amp;&amp; it.@id.startsWith('thread_title_') }
    try5.eachWithIndex { row, i -&gt;
      println "rn: $i"
    }
    // no output
  
  }
  </code></pre>
  
  <p><a href="http://groovy.codehaus.org/gapi/groovy/util/slurpersupport/Attributes.html" rel="nofollow noreferrer">Here</a> is the gdoc for Attributes. I don't really want "name", I want "value". <a href="http://groovy.codehaus.org/GPath" rel="nofollow noreferrer">The gpath page</a> implies that <code>node.character.find { it['@id'] == '2' }</code> works, which seems much like find..startsWith to me. <a href="https://stackoverflow.com/a/7020993/659298">This stackoverflow answer</a> is similar, but the startsWith is different and seems to throw a wrench into the whole thing. The fifth entry was <a href="https://stackoverflow.com/questions/7020843/how-to-find-element-by-attribute-value-in-gpath">inspired by this stackoverflow answer</a>.</p>
  
  <p>And if you are concerned it's a problem with the input data:
      $ curl --silent <a href="http://www.advrider.com/forums/forumdisplay.php?f=18" rel="nofollow noreferrer">http://www.advrider.com/forums/forumdisplay.php?f=18</a> | grep thread_title | wc -l
      43</p>
  
  <p>Here is some sample output, using the <code>curl | grep</code> above.</p>
  
  <pre><code>&lt;a href="foo" id="thread_title_705760"&gt;text&lt;/a&gt;
  &lt;a href="foo" id="thread_title_753701"&gt;text&lt;/a&gt;
  </code></pre>
  
  <p>I have Groovy 1.7.10 installed. I could go newer, don't know if it would help.</p>