Get href from leftmost column in table with XPath
<p>I am attempted to extract <code>href</code> text from a table here: <a href="https://en.wikipedia.org/wiki/List_of_first-person_shooters" rel="nofollow">https://en.wikipedia.org/wiki/List_of_first-person_shooters</a></p>

<p>Here is the top of the table:</p>

<pre><code>&lt;table class="wikitable sortable" style="font-size: 85%; text-align: left;"&gt;
&lt;tr style="background: #ececec"&gt;
&lt;th&gt;Title&lt;/th&gt;
&lt;th&gt;Developer&lt;/th&gt;
&lt;th&gt;Platform(s)&lt;/th&gt;
&lt;th&gt;Release Date&lt;/th&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;th&gt;&lt;i&gt;&lt;a href="/wiki/007_Legends" title="007 Legends"&gt;007 Legends&lt;/a&gt;&lt;/i&gt;&lt;/th&gt;
&lt;td&gt;&lt;a href="/wiki/Eurocom" title="Eurocom"&gt;Eurocom&lt;/a&gt;, &lt;a href="/wiki/Activision" title="Activision"&gt;Activision&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;PS3, X360, Wii U, WIN&lt;/td&gt;
&lt;td&gt;2012-10-16&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;th&gt;&lt;i&gt;&lt;a href="/wiki/007:_Quantum_of_Solace" title="007: Quantum of Solace"&gt;007: Quantum of Solace&lt;/a&gt;&lt;/i&gt;&lt;/th&gt;
&lt;td&gt;&lt;a href="/wiki/Treyarch" title="Treyarch"&gt;Treyarch&lt;/a&gt;, &lt;a href="/wiki/Beenox" title="Beenox"&gt;Beenox&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;DS, PS3, Wii, WIN, X360&lt;/td&gt;
&lt;td&gt;2008-10-31&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;th&gt;&lt;i&gt;&lt;a href="/wiki/3D_Monster_Chase" title="3D Monster Chase"&gt;3D Monster Chase&lt;/a&gt;&lt;/i&gt;&lt;/th&gt;
&lt;td&gt;&lt;a href="/w/index.php?title=Romik&amp;amp;action=edit&amp;amp;redlink=1" class="new" title="Romik (page does not exist)"&gt;Romik&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;AMSCPC, ZX&lt;/td&gt;
&lt;td&gt;1985&lt;/td&gt;
&lt;/tr&gt;
</code></pre>

<p>The following XPath query obtains the href text from the table, but I only want the first column from each row. Is this possible with XPath, preferable without counters? I am using Python library <code>lxml</code>:</p>

<pre><code>tree.xpath('//table[@class="wikitable sortable"]//a/@href')
</code></pre>

<p>retrieves:</p>

<pre><code>['/wiki/007_Legends', '/wiki/Eurocom', '/wiki/Activision', '/wiki/007:_Quantum_of_Solace', '/wiki/Treyarch', '/wiki/Beenox', '/wiki/3D_Monster_Chase', '/w/index.php?title=Romik&amp;action=edit&amp;redlink=1', '/wiki/Ace_of_Spades_(video_game)', '/w/index.php?title=Ben_Aksoy&amp;action=edit&amp;redlink=1', '/wiki/Alcatraz:_Prison_Escape', '/wiki/Zombie_Studios', '/wiki/CodeRED:_Alien_Arena', '/w/index.php?title=COR_Entertainment&amp;action=edit&amp;redlink=1', '/wiki/FreeBSD', '/wiki/Alien_Breed_3D', '/wiki/Team17', '/wiki/Alien_Breed_3D_II:_The_Killing_Grounds', '/wiki/Team17', 
</code></pre>

<p>However, I would like only the first item in each row</p>

<p>Only first column use <code>&lt;th&gt;</code> and <code>&lt;i&gt;</code> so use it</p>

<pre><code>tree.xpath('//table[@class="wikitable sortable"]//th//a/@href')
</code></pre>

<p>or</p>

<pre><code>tree.xpath('//table[@class="wikitable sortable"]//i/a/@href')
</code></pre>

python html xml xpath lxml