#python 我从网上学了一个秒杀脚本,从网上查了WebDriver提供的8种元素定位方法,但为什么这里显示WebDriver没有这个方法啊find_element_by_link_text',求告知
from selenium import webdriver
import datetime
import time
# 连接Chrome浏览器
driver = webdriver.Chrome()
def login(url):
# 打开淘宝登录页,并进行登录
driver.get("https://www.taobao.com/")
time.sleep(3)
if driver.find_element_by_link_text("亲,请登录"):
driver.find_element_by_link_text("亲,请登录").click()
print("请在20秒内完成登录")
time.sleep(3)
driver.get(url)
time.sleep(3)
now = datetime.datetime.now()
print('login success:',now.strftime('%Y-%m-%d %H:%M:%S'))
def buy(buytime):
while True:
now = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
# 对比时间 ,时间到的话点击结算
if now >= buytime:
try:
# 立即抢购
if driver.find_element_by_id("J_LinkBuy"):
print("速度点击!!!")
driver.find_element_by_id("J_LinkBuy").click()
time.sleep(0.09)
while now >= buytime:
try:
print('正在提交订单')
if driver.find_element_by_class_name('go-btn'):
driver.find_element_by_class_name('go-btn').click()
except:
time.sleep(0.02)
except:
time.sleep(0.08)
print(now)
time.sleep(0.05)
if __name__ == "__main__":
times = input('请输入抢购时间:时间格式:2021-12-29 19:45:00.000000')
url = input('请输入抢购地址')
login(url)
buy(times)
运行结果及报错内容
Traceback (most recent call last):
File "C:\Users\32739\Desktop\python自动化\shopping_taobao.py", line 48, in <module>
login(url)
File "C:\Users\32739\Desktop\python自动化\shopping_taobao.py", line 12, in login
if driver.find_element_by_link_text("亲,请登录"):
AttributeError: 'WebDriver' object has no attribute 'find_element_by_link_text'
我想要达到的结果
使整个代码能够正常运行