views:

129

answers:

1

I have the following function

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

I would to see the content of post. I have tried everything I can think of.

How can I properly debug the content? This is an website of movies where I'm rip links and title and this function should parse the title.

I am sure H@ is not existing, how can I print/debug this?

+1  A: 

post is lxml element tree object, isn't it? so first, you could try:

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

if isn't, you should create element tree object from it

post = lxml.html.fromstring(post)

or maybe the problem is just that you should replace h2 with //h2?

your question is not very explanatory..

mykhal