我想提取td中所有类为u-ctitle的链接。我的xpath表达式有什么问题?
import os
import urllib
import lxml.html
down='http://v.163.com/special/opencourse/bianchengdaolun.html'
file=urllib.urlopen(down).read()
root=lxml.html.document_fromstring(file)
namelist=root.xpath('//td[@class="u-ctitle"]/a')
len(namelist)
输出[],有这么多的TD,其经“U型ctitle”,用萤火你CA得到的,为什么不能提取呢?
这是没有用的,更改文件到其他名称。
您能分享网页中的html吗? – Shijo
由于len()应该返回整数,所以输出不能是空列表('[]')而且你的'XPath'也能正常工作(在'Python 3.5'上试过,''用来代替'urllib ' - output'34').. – Andersson
用Python 2.7.5确认,工作和列表是不是空的。你确定你得到'[]'作为输出吗? –