中午写的 细节肯定没做, 就是个大概的流程
登录你的网盘
上传文件(只写了上传到根目录)
就这么个流程
话说lanzou登录 密码连个md5都没做 , 被截包密码就明文显示了
- import requests, json, os
- from lxml import etree
- from clint.textui.progress import Bar as ProgressBar
- from requests_toolbelt import MultipartEncoder, MultipartEncoderMonitor
- def create_callback(encoder):
- bar = ProgressBar(expected_size=encoder.len, filled_char=’=’)
- def callback(monitor):
- bar.show(monitor.bytes_read)
- return callback
- def getFormHash():
- url = "https://pc.woozooo.com/account.php?action=login&ref=/mydisk.php"
- headers = {
- ‘user-agent’: ‘Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36’,
- }
- print("获取formhash中…")
- r = session.get(url, headers=headers)
- html = etree.HTML(r.text)
- formhash = html.xpath(‘//input[@name="formhash"]/@value’)[0]
- print("formhash : %s" % formhash)
- print(‘*’*20)
- return formhash
- def login(formhash, username, password):
- print("username = %s, password = %s" % (username, password))
- print("登录中…")
- url = "https://pc.woozooo.com/account.php"
- durl = "https://pc.woozooo.com/mydisk.php"
- headers = {
- ‘content-type’: ‘application/x-www-form-urlencoded’,
- ‘referer’: ‘https://pc.woozooo.com/account.php?action=login&ref=/mydisk.php’,
- ‘user-agent’: ‘Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36’,
- }
- formdata = {
- ‘action’: ‘login’,
- ‘task’: ‘login’,
- ‘ref’: ‘/mydisk.php’,
- ‘formhash’: formhash,
- ‘username’: username,
- ‘password’: password,
- }
- r = session.post(url, data=formdata, headers=headers)
- r = session.get(durl)
- keyword = "mydisk.php?item=files&action=index&u=" + username
- if keyword in r.text:
- print("登录成功…")
- else:
- exit("登录出错, 退出程序!")
- print(‘*’*20)
- def uploadFile(file):
- print("上传文件中…")
- fileName = os.path.split(file)[1]
- api = "https://pc.woozooo.com/fileup.php"
- headers = {
- ‘user-agent’: ‘Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36’,
- }
- formdata = {
- ‘task’: ‘1’,
- ‘folder_id’: ‘-1’,
- ‘type’: ‘application/octet-stream’,
- ‘upload_file’: (fileName,open(file, ‘rb’), ‘application/octet-stream’)
- }
- encoder = MultipartEncoder(formdata)
- callback = create_callback(encoder)
- monitor = MultipartEncoderMonitor(encoder, callback)
- headers[‘Content-Type’] = monitor.content_type
- r = session.post(api, data=monitor, headers=headers)
- print(‘\nUpload finished! (Returned status {0} {1})’.format(
- r.status_code, r.reason
- ))
- print(json.loads(r.text))
- print(‘*’*20)
- if __name__ == "__main__":
- config = {
- ‘username’: ‘用户名’,
- ‘password’: ‘密码’,
- }
- session = requests.session()
- login(getFormHash(), **config)
- fileList = [‘D:\备份\phpStudy.zip’, ‘D:\备份\WinSCP.rar’]
- for file in fileList:
- uploadFile(file)
复制代码
安徽网友:那是没https
浙江网友:不错不错,python还是方便啊