-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtestGettingProce.py
More file actions
51 lines (42 loc) · 1.41 KB
/
testGettingProce.py
File metadata and controls
51 lines (42 loc) · 1.41 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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
from _init_ import getDriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import NoSuchElementException
import time
def getPrice(driver):
price = 0
try:
price = driver.find_element_by_id('priceblock_ourprice').text
price = convert_price(price)
except NoSuchElementException:
try:
availability = driver.find_element_by_id('availability').text
if 'Available' in availability:
price = driver.find_element_by_class_name('olp-padding-right').text
price = convert_price(price[price.find("$"):])
except Exception as e:
return None
except Exception as e:
return None
return price
def convert_price(price):
price = price.split("$")[1]
try:
price = price.split("\n")[0] + "." + price.split("\n")[1]
except:
Exception()
try:
price = price.split(",")[0] + price.split(",")[1]
except:
Exception()
return float(price)
def getname(driver):
try:
return driver.find_element_by_id('productTitle').text
except Exception as e:
return None
def getData(url, ref):
driver = getDriver(ref)
driver.get(url)
return [getPrice(driver), getname(driver)]