-
Notifications
You must be signed in to change notification settings - Fork 0
/
target.py
35 lines (27 loc) · 1.13 KB
/
target.py
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
33
34
35
import asyncio
from playwright.async_api import async_playwright, TimeoutError as PlaywrightTimeoutError
'''
2 different cases:
(A) Search a common element and check it has out of stck text
(B) Find an element that points that product is available -> outStockText = null
'''
class PlayWrightTarget:
def __init__(self, vendor, url, checkElement, outStockText):
self.vendor = vendor
self.url = url
self.checkElement = checkElement
self.outStockText = outStockText
async def check_vendor(self, browser):
page = await browser.new_page()
await page.goto(self.url, wait_until="commit") #Default until load generate timeout in Amazon
try:
web_element = await page.text_content(self.checkElement, timeout=10000)
except PlaywrightTimeoutError: # If web_element is not found, it is case B with no stock
await page.close()
return False
if self.outStockText is not None: #CASE A
if self.outStockText in web_element:
await page.close()
return False
await page.close()
return True