这两天收到朋友委托帮忙淘宝抢个东西
不多说,上代码
asyncio不太会,就当个多开selenium的工具用了
# don't forget to write today
# ------Dunn White
# 2022/8/31 15:54
#模拟登录淘宝,下单
#怎么提高成功概率?
#for a in
import selenium
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver import ActionChains
from time import sleep
from chaojiying_Python import chaojiying
#PIL年久失修了,下载的时候下载Pillow(导包的时候还是导PIL)
from PIL import Image
import json
import requests
import asyncio
#asyncio在await sleep过程中运行其他部分的内容
#可以同时运行几个程序,但是只有在sleep(也就是加载)的过程中可以转到其他浏览器进行操作
async def func():
ed1 = webdriver.Edge()
#这里的链接填自己购物车的连接
ed1.get("https://cart.taobao.com/cart.htm?spm=a1z02.1.a2109.d1000367.sfEIm6&nekot=1470211439694")
await asyncio.sleep(1)
ed1.maximize_window()
await asyncio.sleep(5)
#去除识别码,不然会出现滑块认证
script = 'Object.defineProperty(navigator, "webdriver", {get: () => false,});'
ed1.execute_script(script)
box1=ed1.find_element(By.XPATH,'//*[@id="fm-login-id"]').send_keys("账号")
box2=ed1.find_element(By.XPATH,'//*[@id="fm-login-password"]').send_keys("密码")
#<button type="submit" tabindex="3" class="fm-button fm-submit password-login">登录</button>
button1=ed1.find_element(By.XPATH,'//*[@id="login-form"]/div[4]/button')
button1.click()
await asyncio.sleep(7)
#这里的XPATH输入购物车内目标物品选择框的xpath
checkbox=ed1.find_element(By.XPATH,'//*[@id="J_Order_s_2212057548173_1"]/div[1]/div/div/label')
#checkbox=ed1.find_element(By.XPATH,'//*[@id="J_Item_2892242466094"]/ul/li[1]/div/div/div/label')
checkbox.click()
await asyncio.sleep(1)
deal=ed1.find_element(By.XPATH,'//*[@id="J_SmallSubmit"]')
deal.click()
print("查找结果", deal)
await asyncio.sleep(8)
deal_made=ed1.find_element(By.XPATH,'//*[@id="submitOrderPC_1"]/div/a[2]')
print("查找结果",deal_made)
deal_made.click()
#<input name="fm-login-password" type="password" class="fm-text" id="fm-login-password" tabindex="2" aria-label="请输入登录密码" placeholder="请输入登录密码" maxlength="40" autocapitalize="off">
#await asyncio.sleep(80)
#<a id="J_LinkBuy" href="#" rel="nofollow" data-addfastbuy="true" title="点击此按钮,到下一步确认购买信息。" role="button">立即购买<span class="ensureText">确认</span></a>
#<a role="button" title="提交订单" class="go-btn" style="background-color: rgb(255, 0, 54);">提交订单</a>
async def main1():
num1=0
li1=[]
for url1 in range (0,5):
task1=asyncio.create_task(func())
li1.append(task1)
num1+=1
await asyncio.wait(li1)
asyncio.run(main1())