我有一个场景,首先我将命中API以获取所有数据并将该数据添加到我的Selenium python脚本中。但是在此之前,我想每当数据库中有一个条目时就自动运行我的脚本。现在写,我正在手动运行我的脚本,我想每当数据库中有一个新条目时就自动运行它。我使用的API基本上是数据库中的条目。因此流程如下:首先,数据库中有一个关于用户的条目,该条目将以API形式出现,每当有一个条目时,我的脚本都应使用API运行。
下面是我的硒脚本
import time
import requests
from selenium import webdriver
base_url="https://www.fitotouch.com"
base_url1= "https://www.fitotouch.com/qitouch"
qty: int=2
cart_value : int = 1
driver = webdriver.Chrome('E:/Chrome driver/chromedriver.exe')
driver.maximize_window()
#function of our 'driver' object.
driver.implicitly_wait(10) #10 is in seconds
driver.get(base_url)
driver.implicitly_wait(10)
driver.find_element_by_name('password').send_keys("*****")
driver.implicitly_wait(10)
driver.find_element_by_class_name('arrow-icon').click()
data = requests.get('http://110.93.230.117:1403/api/order/5e439b7052fcf2189ccb5207').json()
print(data)
driver.implicitly_wait(10)
time.sleep(2.4)
#driver.find_element_by_xpath('//*[@id="header"]/div[2]/div/div[2]/div[3]/div[1]/a/span').click()
time.sleep(2.4)
driver.get('https://www.fitotouch.com/account/login/create')
time.sleep(2.4)
driver.switch_to.frame("accountFrame")
time.sleep(2.4)
driver.find_element_by_xpath('//*[@id="root"]/div/div/div/div[1]/div[1]/div/input').send_keys(data['FirstName'])
driver.find_element_by_xpath('//*[@id="root"]/div/div/div/div[1]/div[2]/div/input').send_keys(data['LastName'])
driver.find_element_by_xpath('//*[@id="root"]/div/div/div/div[2]/div/input').send_keys(data['Email'])
driver.find_element_by_xpath('//*[@id="root"]/div/div/div/div[3]/div/input').send_keys("*****")
driver.find_element_by_xpath('//*[@id="root"]/div/div/div/div[4]/div/input').send_keys("*****")
driver.find_element_by_xpath('//*[@id="root"]/div/div/div/button').click()
driver.get("https://www.fitotouch.com/fitoki/f-001-jing-fang-bai-du-wan")
#product_category=['driver.get("https://www.fitotouch.com/fitoki/f-001-jing-fang-bai-du-wan")','driver.get("https://www.fitotouch.com/soria-chinasor/style-02-hzewl")']
driver.execute_script("window.scrollTo(0, 150)")
time.sleep(2.4)
cart = driver.find_element_by_xpath('/html/body/div[1]/main/article/section/div[2]/div/section/article/section[1]/section/div/div[3]/div/div')
if qty > 0:
for i in range(qty):
cart.click()
time.sleep(2.4)
# print("quantity was" +qty)
else:
cart.click()
url = driver.current_url
print(url)
我有一个场景,首先我将命中API以获取所有数据并将该数据添加到我的Selenium python脚本中。但是在此之前,我想在有条目时自动运行脚本...
我不确定这是否是最好的解决方案,但是想到的是您需要让脚本在while循环中不断运行。在循环外部设置一个变量,该变量代表表中的最新行索引。