selenium 淘宝登陆购买,基础实现
来源:互联网 发布:南粤大数据 编辑:程序博客网 时间:2024/04/30 13:11
主要实现基础的淘宝登陆搜索及购买。
利用selenium + chrome,当然,这个还有以下两个问题:
1. 不够稳定,还有些细节可以做
2. 没封装
先实现流程吧
from selenium import webdriverfrom selenium.webdriver.common.keys import Keysimport timedef login(driver, account, password): #登陆 driver.find_element_by_css_selector('div.site-nav-sign a.h').click() time.sleep(3) js = 'document.getElementById("J_Quick2Static").click()' driver.execute_script(js) driver.find_element_by_id('TPL_username_1').send_keys(account) time.sleep(1) driver.find_element_by_id('TPL_password_1').send_keys(password) time.sleep(2) try: driver.find_element_by_id('J_SubmitStatic').click() except: print('账号或密码错误!') pass time.sleep(3) return driverdef search_buy(driver, keyword, first_handle): #搜索购买 elem = driver.find_element_by_id('q') elem.send_keys(keyword) elem.send_keys(Keys.RETURN) time.sleep(2) #购买第一个商品 elem2 = driver.find_elements_by_css_selector('a.J_ClickStat')[1] elem2.click() time.sleep(1) all_handles = driver.window_handles #print(all_handles) for handle in all_handles: if handle == first_handle: pass else: print(handle) driver.switch_to.window(handle) driver.find_element_by_id('J_LinkBuy').click() time.sleep(2) return driverdef num_for_charge(driver, num): #输入充值手机号 driver.find_element_by_id('pAccount').send_keys(num) time.sleep(1) driver.find_element_by_id('rpAccount').send_keys(num) time.sleep(1) try: driver.find_element_by_id('J_PerformSubmit').click() except: print("手机号码不对") pass time.sleep(3) return driverdef make_payment(driver, paypwd): #输入支付宝密码支付 driver.find_element_by_id('payPwd').send_keys(paypwd) time.sleep(1) driver.find_element_by_id('payPwdConfirm').send_keys(paypwd) time.sleep(1) driver.find_element_by_id('J-submit').click() time.sleep(1) driver.quit() return print('finish!')if __name__ == '__main__': url = 'https://www.taobao.com/' driver = webdriver.Chrome() driver.get(url) drivers = login(driver, "账户名", "密码") first_handle = driver.current_window_handle drivers = search_buy(drivers,"移动充值", first_handle) drivers = num_for_charge(drivers, "充值手机号") make_payment(drivers, "付款密码")
0 0
- selenium 淘宝登陆购买,基础实现
- selenium、python模拟登陆淘宝
- python+selenium+phantomjs 模拟淘宝登陆
- Python+Selenium 持续化传递Cookie登陆淘宝 实践
- ecshop 实现qq,新浪,淘宝登陆接口
- python+selenium实现登陆保存cookie
- 淘宝登陆
- 美国VPS淘宝购买地址
- 淘宝坑爹购买纪录
- selenium(二)之实现淘宝登录并计算个人淘宝总支出
- 基于selenium登录淘宝
- 淘宝爬虫(Selenium)
- python利用selenium获取cookie实现免登陆
- python 登陆开心网图片批量下载-selenium实现
- 基于python 3 的selenium模块实现网页自动登陆
- python爬虫selenium模块实现登陆(浅)
- 【基础6】selenium实现文件上传
- android 淘宝登陆授权
- Cento 常见错误
- 内省
- 25. Reverse Nodes in k-Group
- 汇编求字符串中空格的个数
- centos 安装mongodb
- selenium 淘宝登陆购买,基础实现
- 回滚到任意版本
- 2017跟着小虎玩着去软考--项目管理师上午考试试题之七(解析2016下半年信息系统项目管理师上午试题24-28题)
- 折半查找
- leetcode 432. All O`one Data Structure
- 深度 | David Silver全面解读深度强化学习:从基础概念到AlphaGo
- 【TJOI2014】匹配(match)
- 问佛> 归去来兮
- Android Activity 启动模式(续) 和显/隐式的intent