lxml XPath - extracting text from multi p nodes
<h2>Please have a look at <a href="http://stackoverflow.com/questions/39242154/lxml-xpath-position-does-not-work">lxml XPath position() does not work</a> first.</h2>

<p>Since XPath does not support to extract text from multi nodes, I decided to write for loop to get 30 stuffs.</p>

<pre><code>for i in range(1,31):
    content = "string(//div[@id='article']/p[" + (print(i)) + "]/.)"
    print(content)
</code></pre>

<p>I imagined it would return like,</p>

<pre><code>"string(//div[@id='article']/p[1]/.)"
"string(//div[@id='article']/p[2]/.)"
"string(//div[@id='article']/p[3]/.)"
....
"string(//div[@id='article']/p[30]/.)"  
</code></pre>

<p>However, obviously it does not work as I expected.. I got error message as following.</p>

<pre><code>TypeError: Can't convert 'NoneType' object to str implicitly
</code></pre>

<p>What should I do? Any other elegant approach to solve this problem?</p>

<p>The trailing <code>/.</code> in your xpath is invalid. </p>

<p>Try: </p>

<pre><code>content = "string(//div[@id='article']/p[" + (print(i)) + "])"
</code></pre>

<p>Full example:</p>

<pre class="lang-py prettyprint-override"><code>import lxml.html

html = """&lt;tag1&gt;
&lt;tag2&gt;
&lt;div id="article"&gt;
&lt;p&gt; stuff1 &lt;/p&gt;
&lt;p&gt; stuff2 &lt;/p&gt;
&lt;p&gt; stuff30 &lt;b&gt;more stuff&lt;/b&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;/tag2&gt;
&lt;/tag1&gt;"""

root = lxml.html.fromstring(html)

for i in range(1,4):
    content = root.xpath("string(//div[@id='article']/p[" + str(i) + "])")
    print(content)
    #stuff1
    #stuff2
    #stuff30 more stuff
</code></pre>

python python-3.x xpath lxml