Using xpath to extract date
<p>I'm trying to extract the date from a webpage, '07/18/16' in the comment below. I'm not clear on the syntax for xpath, how would you grab just the date?</p>

<pre><code>#&lt;p&gt;Opened &lt;a class="timeline" href="/trac3/timeline?from=2016-07-    
#18T14%3A46%3A43-04%3A00&amp;amp;precision=second" title="See timeline at   
#07/18/16 14:46:43"&gt;6 weeks ago&lt;/a&gt;&lt;/p&gt;

from lxml import html
import requests

page = requests.get(webpage)
tree = html.fromstring(page.content)

openDate = tree.xpath('//Opened/text()')

print 'Open Date: ', openDate
</code></pre>

<p>You cant do this. Xpath directly choose tag, not fields in it.
So "//p/a[text()]" return all <code>&lt;a class="timeline" href="/trac3/timeline?from=2016-07-18T14%3A46%3A43-04%3A00&amp;amp;precision=second" title="See timeline at 07/18/16 14:46:43"&gt;6 weeks ago&lt;/a&gt;</code>
Or you can choose by condition like "//p/a[text() = "6 weeks ago"]"
So get this <code>&lt;a&gt;&lt;/a&gt;</code> tag and then parse it with python</p>

python regex xpath python-requests lxml