python mongo 存储出错 : cannot encode object

lonelyriver 2019-09-13 12:22:46

db.news.insert_one({'news_id': i,'news_title':news_title,'update_time':update_time,'content':content.decode()})

content存储的是网页源代码 可以正常运行不报错。。
用bs4替换了原先网页中的src地址(由相对地址改为了绝对地址) 然后报一下错误:
bson.errors.InvalidDocument: cannot encode object: <img class="raw-image" data-ratio="1" data-type="
jpeg" data-w="258" src="http://www.semiinsights.com/uploadfile/2019/0912/20190912020014587.jpg"/>, o
f type: <class 'bs4.element.Tag'>

如何解决求大神指点。
...全文
761 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

37,720

社区成员

发帖
与我相关
我的任务
社区描述
JavaScript,VBScript,AngleScript,ActionScript,Shell,Perl,Ruby,Lua,Tcl,Scala,MaxScript 等脚本语言交流。
社区管理员
  • 脚本语言(Perl/Python)社区
  • IT.BOB
加入社区
  • 近7日
  • 近30日
  • 至今

试试用AI创作助手写篇文章吧