AttributeError: 'function' object has no attribute 'Html'
导入etree模块后,etree后无法输入HTML方法,强行写上运行提示"lxml“没有HTML属性。python版本3.92,跪求大佬们帮下。AttributeError: 'function' object has no attribute 'Html' 连代码都不贴吗
还是你的代码文件名和系统模块重名呢 看这报错 大概率是函数后面没有加() import requests
from lxml import etree
if __name__ == '__main__':
url="https://www.huya.com/g/4079"
headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36"
}
page_text=requests.get(url=url,headers=headers).text
tree=etree.HTML(page_text)
r=tree.xpath('//img[@class="pic"]/@src')
代码没问题,网上说python3.5以后LXML里都没有了etree。
页:
[1]