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

Posted wangcongxing

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了使用selenium 自动将京东购物车加满相关的知识,希望对你有一定的参考价值。

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

     请参考上一篇博文

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

# 导入selenium 模块
from selenium import webdriver
from time import sleep
# 添加驱动
bro = webdriver.Chrome(executable_path="D:webLogingoogleDriverchromedriver.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 自动将京东购物车加满的主要内容,如果未能解决你的问题,请参考以下文章