1 Star 0 Fork 0

Zsheng/baidudownload

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
6.py 1.75 KB
一键复制 编辑 原始数据 按行查看 历史
tianzhongsheng 提交于 2020-03-09 12:51 . ‘1’
# coding=utf-8
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
import time
import pickle
def save_cookies(requests_cookiejar, filename):
with open(filename, 'wb') as f:
pickle.dump(requests_cookiejar, f, 0)
url = 'https://pan.baidu.com/s/1lgSXM9s1XwLVtI3PTTKJSg'
tqm = 'j5pj'
tqmCssId = 'ktlJmA'
clickName = 'ivirlGXq'
cookies_file = '/Users/zhongsheng/test/baidu.cookies'
driver = webdriver.Chrome(ChromeDriverManager().install())
driver.refresh()
driver.get(url)
elem = driver.find_element_by_id(tqmCssId)
elem.send_keys(tqm)
element = driver.find_element_by_id(clickName)
driver.execute_script("arguments[0].click();", element)
# 下载页面
time.sleep(2)
driver.find_element_by_xpath("//a[@data-button-id='b3']").click()
# 开始登陆
time.sleep(2)
driver.find_element_by_id("TANGRAM__PSP_10__footerULoginBtn").click()
userName = '15611658186'
userPassword = '1986630tian168'
# userName = '18366189397'
# userPassword = 'baidu1001'
userNameCssId = 'TANGRAM__PSP_10__userName'
userPasswordCssId = 'TANGRAM__PSP_10__password'
submits = 'TANGRAM__PSP_10__submit'
driver.find_element_by_id(userNameCssId).send_keys(userName)
driver.find_element_by_id(userPasswordCssId).send_keys(userPassword)
driver.find_element_by_id(submits).click()
time.sleep(10) # 等登录加载完成
cookies = driver.get_cookies()
print(cookies)
# pickle.dump(driver.get_cookies(), open(cookies_file, "wb"))
# save_cookies(cookies, cookies_file)
# jsonCookies = json.dumps(cookies)
# # print(jsonCookies)
# with open(cookies_file, 'w') as f:
# f.write(jsonCookies)
# save_cookies(cookies, '/Users/zhongsheng/test/baidu.cookies')
# save_cookies(cookies, cookies_file)
# 链接: https://pan.baidu.com/s/1lgSXM9s1XwLVtI3PTTKJSg 提取码: j5pj
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/zsheng168/baidudownload.git
git@gitee.com:zsheng168/baidudownload.git
zsheng168
baidudownload
baidudownload
master

搜索帮助