使用selenium 自动将京东购物车加满

项目运行环境以及需要安装的包

     请参考上一篇博文

      https://www.cnblogs.com/wangcongxing/p/13060300.html

# 导入selenium 模块
from selenium import webdriver
from time import sleep
# 添加驱动
bro = webdriver.Chrome(executable_path="D:\webLogin\googleDriver\chromedriver.exe")
# 访问京东
bro.get("https://www.jd.com")
# 找到搜索的input
search_text = bro.find_element_by_xpath('//*[@id="key"]')
# 输入iphonex
search_text.send_keys("iphonex")
# 点击搜索按钮
btn = bro.find_element_by_xpath('//*[@id="search"]/div/div[2]/button')
btn.click()
sleep(2)
# 点击第一个返回的商品
a_href = bro.find_element_by_xpath('//*[@id="J_goodsList"]/ul/li[1]/div/div[1]/a').get_attribute("href")
bro.get(a_href)
payBtn = bro.find_element_by_xpath('//*[@id="InitCartUrl"]')
payBtn.click()

 

posted @ 2020-06-07 13:37  汪丛兴  阅读(426)  评论(0编辑  收藏  举报