-
Notifications
You must be signed in to change notification settings - Fork 122
Open
Description
偶然见到LZ写的文章,非常漂亮。虽然和我的教程思路不一样^^ ,用的 cookie 方法也不一样
大概看了一下代码,没有测试。可以重写 增加 pipeline ,大概是这样,就可以直接在 ans.json 中
看到内容,并且也处理了 Unicode 到 utf-8 的转换
'
import json
import codecs
class doubanBookPipeline(object):
def __init__(self):
self.file = codecs.open('ans.json', 'wb', encoding='utf-8')
def process_item(self, item, spider):
line = json.dumps(dict(item), ensure_ascii=False) + "\n"
self.file.write(line)
return item
def spider_closed(self, spider):
self.file.close()
file = codecs.open(filename,'wb',encoding='utf-8')
'
还有 LZ 的代码现在应该登录不上去了? zhihu.com/login 已经被取消了,换用 zhihu.com 直接提交表单应该就可以。
祝顺利啦~
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels