AttributeError: 'lxml.etree._Element' object has no attribute 'translate'

       此处的错误是我在利用lxml下的etree爬取拉勾网时出现的错误方法:
       把你要爬取的内容用print输出一遍看看是不是存在json数据代码如下:

positionName=html.xpath("//div[@class='position-head']/div/div[1]/div/span")
运行结果:[<Element span at 0x23290bb6ec8>]

解决代码问题:
添加/text()就能提取正确内容,此处的【0】是提取返回list中的每一个字符串

positionName=html.xpath("//div[@class='position-head']/div/div[1]/div/span/text()")[0]

猜你喜欢

转载自blog.csdn.net/work_you_will_see/article/details/84637076