BigEfromDaBX
BigEfromDaBX

Reputation: 177

Getting Xpath from plain text

Im trying to get xpath from text instead of a URL. But i keep getting the error "AttributeError: 'HtmlElement' object has no attribute 'XPath'"

see code below.

from lxml import html

var ='''<html lang="en">
  <head>
    <title>Selecting content on a web page with XPath</title>
  </head>
  <body>
     This is the body
  </body>
</html>
'''

tree = html.fromstring(var)

body = tree.XPath('//*/body')

print(body)

Upvotes: 0

Views: 57

Answers (1)

JLRishe
JLRishe

Reputation: 101700

It has been 15 years since I last used Python, but as far as I can tell, it is a case-sensitive language, and the xpath method is all lowercase.

So try this:

body = tree.xpath('//*/body')

Upvotes: 1

Related Questions