title: grab elements with containing text nokogiri xpath
body: <p>Still learning how to use nokogiri and so far can grab by css elements.There is a page I want to scrape <a href="http://www.bbc.co.uk/sport/football/results" rel="nofollow">http://www.bbc.co.uk/sport/football/results</a>, i want to get all the results for the barclays premier league which can be rendered via an Ajax call, however this is not possible with nokogiri i have read.</p>
  
  <p>So the link i have provided has many results for all different leagues so can i grab only the ones which are titled Barclays Premier League which is contained in </p>
  
  <pre><code>class="competition-title"
  </code></pre>
  
  <p>so far i can grab all results like so</p>
  
  <pre><code>def get_results # Get me all results
   doc = Nokogiri::HTML(open(RESULTS_URL))
   days = doc.css('#results-data h2').each do |h2_tag|
   date = Date.parse(h2_tag.text.strip).to_date
    matches = h2_tag.xpath('following-sibling::*[1]').css('tr.report')
    matches.each do |match|
      home_team = match.css('.team-home').text.strip
      away_team = match.css('.team-away').text.strip
      score = match.css('.score').text.strip
   Result.create!(home_team: home_team, away_team: away_team, score: score, fixture_date: date)
  end
  </code></pre>
  
  <p>Any help appreciated</p>
  
  <p>Edit</p>
  
  <p>ok so it seems as if i can use some ruby , using select? not sure how to implement though. example below</p>
  
  <pre><code>.select{|th|th.text =~ /Barclays Premier League/}
  </code></pre>
  
  <p>or some more reading has said xpath can be used</p>
  
  <pre><code>matches = h2_tag.xpath('//th[contains(text(), "Barclays Premier League")]').css('tr.report')
  </code></pre>
  
  <p>or</p>
  
  <pre><code>matches = h2_tag.xpath('//b/a[contains(text(),"Barclays")]/../following-sibling::*[1]').css('tr.report')
  </code></pre>
  
  <p>have tried the xpath way but clearly wrong as nothing saving</p>
  
  <p>Thanks</p>