 <p><code>'x'</code> does not interpolate the <code>x</code> variable into the string. You need to do something like this:</p> <pre><code>xpathName = "/html/body/div[2]/table/tbody/tr[%d]/td[4]//text()" % (x,) xpathTime = "/html/body/div[2]/table/tbody/tr[%d]/td[9]//text()" % (x,) </code></pre> <p>Also, as @grael mentioned, you need to terminate your loop somewhere.</p>