-
Notifications
You must be signed in to change notification settings - Fork 108
Expand file tree
/
Copy pathutil.py
More file actions
42 lines (34 loc) · 1.19 KB
/
Copy pathutil.py
File metadata and controls
42 lines (34 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
__author__ = 'tyz'
import os
import logging
import shutil
def get_yzm(sess, url, path):
yzm = sess.get(url, stream=True)
yzm_jpg_path = os.path.join('log', path)
with open(yzm_jpg_path, 'wb') as f:
yzm.raw.decode_content = True
# f.write(yzm.text.encode('utf8'))
shutil.copyfileobj(yzm.raw, f)
# yzm = yundama(yzm_jpg_path)
print('close jpg, and input the verification code')
os.system(yzm_jpg_path)
x = input('verification code:')
return x
def load_cookie(sess, cookie_path):
sess.cookies.clear()
if os.path.isfile(cookie_path):
with open(cookie_path) as f:
for line in f.read().splitlines():
sp = line.split(',')
if len(sp) == 4:
sess.cookies.set(sp[0], sp[1], domain=sp[2], path=sp[3])
def save_cookie(sess, cookie_path):
# time.sleep(5)
# print(requests.utils.dict_from_cookiejar(sess.cookies))
# print('save cookie', sess.cookies)
try:
with open(cookie_path, 'w') as f:
for c in sess.cookies:
f.write('%s,%s,%s,%s\n' % (c.name, c.value, c.domain, c.path))
except:
logging.warning('save cookie error')