Note that there are some explanatory texts on larger screens.

plurals
  1. POIssues a longer xpath expression
    primarykey
    data
    text
    <p>I am having issues with the <code>urllib</code> and <code>lxml.html</code> modules.</p> <p>Here is my original code:</p> <pre><code>import urllib import lxml.html down='http://v.163.com/special/visualizingdata/' file=urllib.urlopen(down).read() root=lxml.html.document_fromstring(file) xpath_str="//div[@class='down s-fc3 f-fl']/a" urllist=root.xpath(xpath_str) for url in urllist: print url.get("href") </code></pre> <p>When run, it returns this output: </p> <pre><code>http://mov.bn.netease.com/movieMP4/2012/12/A/7/S8H1TH9A7.mp4 http://mov.bn.netease.com/movieMP4/2012/12/D/9/S8H1ULCD9.mp4 http://mov.bn.netease.com/movieMP4/2012/12/4/P/S8H1UUH4P.mp4 http://mov.bn.netease.com/movieMP4/2012/12/B/V/S8H1V8RBV.mp4 http://mov.bn.netease.com/movieMP4/2012/12/6/E/S8H1VIF6E.mp4 http://mov.bn.netease.com/movieMP4/2012/12/B/G/S8H1VQ2BG.mp4 </code></pre> <p>But, when I change the line </p> <p><code>xpath_str='//div[@class="down s-fc3 f-fl"]//a'</code></p> <p>into </p> <p><code>xpath_str='//div[@class="col f-cb"]//div[@class="down s-fc3 f-fl"]//a'</code> </p> <p>that is to say, </p> <pre><code>urllist=root.xpath('//div[@class="col f-cb"]//div[@class="down s-fc3 f-fl"]//a') </code></pre> <p>I do not receive any output. What is the flaw in this code?<br> it is so strange that the shorter one can work,the longer one can not,they have the same xpath structure!</p> <p>open the web '<a href="http://v.163.com/special/visualizingdata/" rel="nofollow noreferrer">http://v.163.com/special/visualizingdata/</a>' in firefox ,you can see the html structure with firebug.</p> <p><img src="https://i.stack.imgur.com/FDwtF.png" alt="enter image description here"></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload