模拟登陆后报错

来源:7-5 网页302之后的模拟登录和cookie传递(网站需要登录时学习本视频教程)

慕仰7968168

2020-04-02

Traceback (most recent call last):
File “/Users/undefeated/Library/Python/3.7/lib/python/site-packages/twisted/internet/defer.py”, line 654, in _runCallbacks
current.result = callback(current.result, *args, **kw)
File “/Users/undefeated/ArticleSpider/ArticleSpider/pipelines.py”, line 38, in process_item
lines=json.dumps(dict(item),ensure_ascii=False)+"\n"
File “/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/json/init.py”, line 238, in dumps
**kw).encode(obj)
File “/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/json/encoder.py”, line 199, in encode
chunks = self.iterencode(o, _one_shot=True)
File “/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/json/encoder.py”, line 257, in iterencode
return _iterencode(o, 0)
File “/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/json/encoder.py”, line 179, in default
raise TypeError(f’Object of type {o.class.name} '
TypeError: Object of type datetime is not JSON serializable

写回答

1回答

bobby

2020-04-03

//img1.sycdn.imooc.com/szimg/5e86b566092dbee107570105.jpg 你的这行代码中的item有datetime类型的值,。直接使用json.dumps遇到这种类型会报错  https://stackoverflow.com/questions/11875770/how-to-overcome-datetime-datetime-not-json-serializable 可以看看这个

0
0

Scrapy打造搜索引擎 畅销4年的Python分布式爬虫课

带你彻底掌握Scrapy,用Django+Elasticsearch搭建搜索引擎

5796 学习 · 6290 问题

查看课程