1

我有以下功能

def parseTitle(self,  post):
    """
        Returns title string with spaces replaced by dots
    ""        
    return post.xpath('h2')[0].text.replace('.',  ' ')

我想看看的内容post。我已经尝试了我能想到的一切。

如何正确调试内容?这是一个电影网站,我在其中翻录链接和标题,这个函数应该解析标题。

我确定 H@ 不存在,我该如何打印/调试它?

4

1 回答 1

2

post是 lxml 元素树对象,不是吗?所以首先,你可以尝试:

# import lxml.html # if not yet imported
# (or you can use lxml.etree instead of lxml.html)
print lxml.html.tostring(post)

如果不是,您应该从中创建元素树对象

post = lxml.html.fromstring(post)

或者问题可能只是你应该替换h2//h2?

你的问题不是很解释..

于 2010-05-06T09:56:17.460 回答