-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest2.py
More file actions
32 lines (29 loc) · 1.57 KB
/
test2.py
File metadata and controls
32 lines (29 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
import time,random
options = Options()
#options.add_argument('--headless')# 无头模式启动
options.add_argument('--disable-gpu')# 谷歌文档提到需要加上这个属性来规避bug
options.add_argument('log-level=3')
options.add_argument('Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.75 Safari/537.36')
url1='https://www.esteelauder.com/product/14324/59459/product-catalog/whats-new/gifts/repair-and-renew/for-firmer-radiant-looking-skin'
url2='https://www.esteelauder.com/product/681/61891/product-catalog/skincare/daywear/anti-oxidant-72h-hydration-sorbet-creme-spf-15'
driver= webdriver.Chrome(options=options)
driver.get(url2)#获取页面
#time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
while True:
driver.refresh()
addButton=driver.find_element_by_class_name("product-full__add-button")
cartCount=driver.find_element_by_class_name("utility-nav__cart-count")
#print(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) +'点击前:'+cartCount.text)
try:
addButton.click()
if cartCount.text!='':
# print(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) +'点击后:'+cartCount.text)
print(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) +'有货'+cartCount.text)
# break
except:
print(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) +'没货')
rn=random.randint(60,180)#随机等待60-180秒
print('等待: '+str(rn)+' 秒')
time.sleep(rn)