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

第十四章[知乎爬虫]--cookie序列化的疑问 #120

Open
yjshi2015 opened this issue Nov 1, 2019 · 0 comments
Open

第十四章[知乎爬虫]--cookie序列化的疑问 #120

yjshi2015 opened this issue Nov 1, 2019 · 0 comments

Comments

@yjshi2015
Copy link

yjshi2015 commented Nov 1, 2019

cookie序列化的代码并没有放在'方法内部',而是跟方法同级的.它是如何被触发执行的?

   # 序列化逻辑
   if not os.path.exists('session.txt'):
       with open('session.txt','wb') as f:
           import pickle
           cookies = response.request.headers['cookie']
           cookieDict={}
           for cookie in cookies.split(';'):
               key,value = cookie[0:cookie.find('=')], cookie[cookie.find('=')+1:]
               cookieDict[key]=value
           pickle.dump(cookieDict,f)

    # 方法
    def parse_user_info(self,response):
        ......
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

1 participant