RicharlyxD
RicharlyxD

Reputation: 125

Convert html to xml Python chilkat

Good morning, I am looking to convert html to xml using chilkat library. but it throws this error at me.

import chilkat 

a = "asd asd asd asd"
xml = a.toXml()
print(xml)
Traceback (most recent call last):                                                                                                                                                                                         
  File "C:\Users\acalobish\Desktop\iaa.py", line 4, in <module>                                                                                                                                                            
    xml = a.toXml()                                                                                                                                                                                                        
AttributeError: 'str' object has no attribute 'toXml'   

Upvotes: 0

Views: 149

Answers (1)

Prince Agrawal
Prince Agrawal

Reputation: 410

import chilkat

htmlToXml = chilkat.CkHtmlToXml()

# Indicate the charset of the output XML we'll want.
htmlToXml.put_XmlCharset("utf-8")

success = htmlToXml.ConvertFile("test.html","out.xml")
if (success != True):
    print(htmlToXml.lastErrorText())
else:
    print("Success")

Upvotes: 1

Related Questions