1
<p>
    Glassware veteran
    <strong>Corning </strong>
    (
    <span class="ticker">
      NYSE:
      <a class="qsAdd qs-source-isssitthv0000001" href="http://caps.fool.com/Ticker/GLW.aspx?source=isssitthv0000001" data-id="203758">GLW</a>
    </span>
    <a class="addToWatchListIcon qsAdd qs-source-iwlsitbut0000010" href="http://my.fool.com/watchlist/add?ticker=&source=iwlsitbut0000010" title="Add to My Watchlist"> </a>
    ) has fallen on hard times lately. Is it time to give up on the stock, or will Corning have a banana and a comeback?
</p>

想入“Glassware 老手”,“最近陷入困境,是时候放弃股票了,还是康宁会一发不可收拾,卷土重来?”

使用代码

tnode = root.xpath("/p")
content = tnode.text

我只能得到“玻璃器老手”,为什么?

4

1 回答 1

0

这样的事情可能会让你得到你想要的:

>>> tnode = root.xpath('/p')
>>> content = tnode.xpath('text()')
>>> print ''.join(content)

Glassware veteran

(


) has fallen on hard times lately. Is it time to give up on the stock, or will Corning have a banana and a comeback?
>>>

如果您想要所有文本节点,只需使用//text()而不是text()

>>> print ' '.join([x.strip() for x in ele.xpath('//text()')])
Glassware veteran Corning ( NYSE: GLW    ) has fallen on hard times lately. Is it time to give up on the stock, or will Corning have a banana and a comeback?
于 2012-12-06T15:13:18.450 回答