title: Self learning regular expression or xpath query?
body: <p>Is  it possible to write code which generates a regular expression or XPath that parses links based on some HTML document?</p>
  
  <p>What I want is to parse a page for some links. The only thing I know is that the majority of the links on the page is those links.</p>
  
  <p>For a simple example, take a Google search engine results page, for example <a href="http://www.google.com/search?hl=en&amp;q=stackoverflow&amp;btnG=Google-search" rel="nofollow noreferrer">this</a>. The majority of the links is from the search results and looks something like this:</p>
  
  <pre><code>&lt;h3 class="r"&gt;&lt;a onmousedown="return rwt(this,'','','res','1','AFQjCNERidL9Hb6OvGW93_Y6MRj3aTdMVA','')" class="l" href="http://stackoverflow.com/"&gt;&lt;em&gt;Stack Overflow&lt;/em&gt;&lt;/a&gt;&lt;/h3&gt;
  </code></pre>
  
  <p>Is it possible to write code that learns this and recognizes this and is able to parse all links, even if Google changes their presentation?</p>
  
  <p>I'm thinking of parsing out all links, and looking X chars before and after each tag and then work from that.</p>
  
  <p>I understand that this also could be done with XPath, but the question is still the same. Can I parse this content and generate a valid XPath to find the serp links?</p>