<table class="genre-table" width="100%" cellpadding="0" cellspacing="0" border="0">
<tbody>
<tr class="odd">
<td width="50%">
<h3>
<a href="http://www.imdb.com/genre/action/?ref_=gnr_mn_ac_mp">Action <span class="normal">»</span>
</a>
</h3>
我想从中提取动作一词,如何编写相关的xpath,请帮忙
我尝试过这个,但没有什么打印出来只是空白->
print genre.xpath('//*[@class="genre-table"]/tbody/tr[1]/td[1]/h3/a/text()')
给出的作品:
>>> import lxml.etree
>>> content='''
<table class="genre-table" width="100%" cellpadding="0" cellspacing="0" border="0">
<tbody>
<tr class="odd">
<td width="50%">
<h3>
<a href="http://www.imdb.com/genre/action/?ref_=gnr_mn_ac_mp">Action <span class="normal"></span>
</a>
</h3></td></tr></tbody></table>'''
>>> genre = lxml.etree.fromstring(content)
>>> print genre.xpath('//*[@class="genre-table"]/tbody/tr[1]/td[1]/h3/a/text()')
['Action ', '\n ']
发生此轮事件有两个常见原因:
curl | less
。本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句