I am trying to master the lxml library for parsing sites. When importing the doctest module ( import lxml.html.usedoctest ), I get an error:

 Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/local/lib/python3.5/site-packages/lxml-3.5.0-py3.5-linux-x86_64.egg/lxml/html/usedoctest.py", line 13, in <module> doctestcompare.temp_install(html=True, del_module=__name__) File "/usr/local/lib/python3.5/site-packages/lxml-3.5.0-py3.5-linux-x86_64.egg/lxml/doctestcompare.py", line 398, in temp_install frame = _find_doctest_frame() File "/usr/local/lib/python3.5/site-packages/lxml-3.5.0-py3.5-linux-x86_64.egg/lxml/doctestcompare.py", line 489, in _find_doctest_frame "Could not find doctest (only use this function *inside* a doctest)") LookupError: Could not find doctest (only use this function *inside* a doctest) 

Maybe someone faced this problem?

I run this code from the manual on the official website:

  from lxml.html import builder as e from lxml.html import usedoctest html = e.HTML( e.HEAD( e.LINK(rel='stylesheet', href='style.css', type='text/css'), e.TITLE('lxml TEst') ), e.BODY( e.H1(e.CLASS('heading'), 'Top news!'), e.DIV('DIV',style='width:100px;height:100px;background:#ccc;') ) ) print(lxml.html.tostring(html)) 
  • Does a from lxml import etree work? - gil9red
  • @ gil9red yes it works - Richat
  • well, then for parsing you have enough: root = etree.XML("...") or root = etree.HTML("...") - gil9red
  • And why do you need usedoctest? It is not needed for parsing sites so much that I don’t even know what it is, although lxml has been running for three years) - andreymal
  • Give a complete (but minimal) example of code that leads to an error. Just in case: the error message says that "this function should be used only inside the doctest ." - jfs

0