Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

listSpider中with open #2

Open
ZZgaoting opened this issue Mar 19, 2019 · 1 comment
Open

listSpider中with open #2

ZZgaoting opened this issue Mar 19, 2019 · 1 comment

Comments

@ZZgaoting
Copy link

with open(fileName, "a+") as f: # 不同人的名言保存在不同的txt文档,“a+”以追加的形式
f.write(text)
f.write('\n') # ‘\n’ 表示换行
f.write('标签:' + tags)
f.write('\n-------\n')
f.close()
是不是不需要f.close()了

@dingyuanhong2006
Copy link

dingyuanhong2006 commented Aug 28, 2019

楼主的这种写法只是简单的描述一下抓取的过程, 更加严谨一点: 可以把对文件的open &保存数据 &close 放到pipelines.py中处理。这样所有的内容就保存到一个文件中了,不会再分成几个文件了,在argsSpider.py中,通过css解析,每次把结果只需要调用 yield item,同时把settings.py中该配置打开即可
ITEM_PIPELINES = {
'argSpider.pipelines.ArgspiderPipeline': 300,
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants