module lxml has no attribute etree错误处理

2020-05-04 17:06:31

问题代码:

import lxml
selector = lxml.etree.HTML(resp.text)

代码报错:AttributeError: module ‘lxml’ has no attribute ‘etree’

处理方法:

使用 lxml.etree之前要import:

import lxml.etree