码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2020-06-07 14:43:14      阅读:119      评论:0      收藏:0      [点我收藏+]

标签:https   wan   lis   from   商品   按钮   输入   attribute   ext   

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

     请参考上一篇博文

      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()

 

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

标签:https   wan   lis   from   商品   按钮   输入   attribute   ext   

原文地址:https://www.cnblogs.com/wangcongxing/p/selenium.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!