-
Notifications
You must be signed in to change notification settings - Fork 0
/
example2.py
56 lines (42 loc) · 1.52 KB
/
example2.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# -*- coding: utf-8 -*-
"""
Created on Wed Mar 18 08:51:21 2020
@author: Demian Jennings
"""
from bs4 import BeautifulSoup
import time
from selenium import webdriver
import csv
def getInventoryList():
# Start browser
driver = webdriver.Chrome()
driver.get('http://eval.arborian.com/')
# dwell time, for any js to load
time.sleep(2)
inventoryList=['296804','198765','750518','688028','127853','261549','382587','389471','251184','601484']
for i in range(34):
pageSource = driver.page_source # Copy page source
bs = BeautifulSoup(pageSource,'html.parser')
table = bs.find('div', id='root')
item_data=table.find('div')
for item in item_data:
small_=item.find_all("small")
quant_group= small_[1].text
inventory, availability = quant_group.split(' ')
if item.h3['id'] in inventoryList and availability=='Available':
master_list.append((item.h3['id'],inventory))
driver.find_element_by_xpath('//*[@id="root"]/div[2]/a[2]').click()
time.sleep(2)
driver.quit()
return
def writeInventoryList(csvFile):
with open(csvFile, 'w',newline='') as f:
fieldnames=['product_id','inventory']
writer = csv.writer(f)
writer.writerow(fieldnames)
for row in master_list:
writer.writerow(row)
return
master_list = []
getInventoryList()
writeInventoryList('inventory.csv')