-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathselenium scraping.py
253 lines (122 loc) · 7.16 KB
/
selenium scraping.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
from selenium import webdriver
from selenium.webdriver.common.by import By
import pandas as pd
from selenium.webdriver.support.ui import Select
from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.common.keys import Keys
import csv
from selenium.webdriver.chrome.options import Options
import chromedriver_autoinstaller
chromedriver_autoinstaller.install()
driver = webdriver.Chrome()
def run():
driver.get('https://checkout.xola.com/index.html?xwm=eyJvcmlnaW4iOiJodHRwczovL2JvaXNlLnB1enpsZWVmZmVjdC5jb20iLCJjaGFubmVsIjoiRmJyd2syd2ZxVnFIRHNhTSJ9&canSendPII=false&popup=false&embeddedCheckout=true&xdm=true&gaPage=%2Fbook-now%2F&gaCode=UA-115829360-2&gaClient=482825549.1675815012&xb_session_seller_website=boise.puzzleeffect.com&xb_session_user_id=63e423d2729469a8daacccbb&xb_session_session_id=63e423d2729469a8daacccbc&xdm_e=https%3A%2F%2Fboise.puzzleeffect.com&xdm_c=default8725&xdm_p=1#buttons/5cba1a789806c5082936aca8')
driver.implicitly_wait(10)
driver.maximize_window()
global df
r=1
datalist = []
while(1):
try:
time = driver.find_element("xpath",'//*[@id="content"]/div/div/div[1]/div/div['+str(r)+']/div/div/div/div[1]').text
title = driver.find_element("xpath",'//*[@id="content"]/div/div/div[1]/div/div['+str(r)+']/div/div/div/div[2]/div[2]/div/div[2]/h3').text
status = driver.find_element("xpath",'//*[@id="content"]/div/div/div[1]/div/div['+str(r)+']/div/div/div/div[2]/div[2]/div/div[3]/div').text
print(status)
Data={ 'Time': time,
'Title': title,
# 'Count': count,
'Available': status}
datalist.append(Data)
df = pd.DataFrame(datalist)
r += 1
# if there are no more table data to scrape
except NoSuchElementException:
break
# saving the dataframe to a csv
df.to_csv('table.csv', index=False)
driver.find_element("xpath", '//*[@id="header"]/div/div[3]/div/button[2]/i').click()
driver.get('https://checkout.xola.com/index.html?xwm=eyJvcmlnaW4iOiJodHRwczovL2JvaXNlLnB1enpsZWVmZmVjdC5jb20iLCJjaGFubmVsIjoiRmJyd2syd2ZxVnFIRHNhTSJ9&canSendPII=false&popup=false&embeddedCheckout=true&xdm=true&gaPage=%2Fbook-now%2F&gaCode=UA-115829360-2&gaClient=482825549.1675815012&xb_session_seller_website=boise.puzzleeffect.com&xb_session_user_id=63e423d2729469a8daacccbb&xb_session_session_id=63e423d2729469a8daacccbc&xdm_e=https%3A%2F%2Fboise.puzzleeffect.com&xdm_c=default8725&xdm_p=1#buttons/5cba1a789806c5082936aca8')
driver.implicitly_wait(10)
driver.maximize_window()
global df
r=1
datalist = []
while(1):
try:
time1 = driver.find_element("xpath",'//*[@id="content"]/div/div/div[1]/div/div['+str(r)+']/div/div/div/div[1]').text
title = driver.find_element("xpath",'//*[@id="content"]/div/div/div[1]/div/div['+str(r)+']/div/div/div/div[2]/div[2]/div/div[2]/h3').text
available = driver.find_element("xpath",'//*[@id="content"]/div/div/div[1]/div/div['+str(r)+']/div/div/div/div[2]/div[2]/div/div[3]/div').text
print(status)
Data={ 'Time': time1,
'Title': title,
'Available': available}
datalist.append(Data)
df = pd.DataFrame(datalist)
r += 1
# if there are no more table data to scrape
except NoSuchElementException:
break
# saving the dataframe to a csv
df.to_csv('table.csv', index=False)
driver.close()
if __name__=="__main__":
run()
--------------------------------------------------
from selenium import webdriver
from selenium.webdriver.common.by import By
import pandas as pd
import time
from selenium.webdriver.support.ui import Select
from selenium.common.exceptions import NoSuchElementException
from selenium.common.exceptions import StaleElementReferenceException
from selenium.webdriver.common.keys import Keys
import csv
import chromedriver_autoinstaller
chromedriver_autoinstaller.install()
driver = webdriver.Chrome()
datalist = []
def run():
driver.get('https://escapethisboise.com/book-now')
driver.implicitly_wait(10)
driver.maximize_window()
global df
week_scrap()
print("first scraping")
next_scrap()
def week_scrap():
time.sleep(3)
r=1
while(1):
try:
time1 = driver.find_element('xpath','//*[@id="content"]/div/div/div[1]/div/div['+str(r)+']/div/div/div/div[1]').text
# time = driver.find_element('xpath','/html/body/div[1]/div/section[3]/section[1]/div[1]/div/div/div[1]/div/div['+str(r)+']/div/div/div/div[1]').text
title = driver.find_element('xpath','//*[@id="content"]/div/div/div[1]/div/div['+str(r)+']/div/div/div/div[2]/div[2]/div/div[2]/h3').text
# title = driver.find_element("xpath",'/html/body/div[1]/div/section[3]/section[1]/div[1]/div/div/div[1]/div/div['+str(r)+']/div/div/div/div[2]/div[2]/div/div[2]/h3').text
available = driver.find_element('xpath','//*[@id="content"]/div/div/div[1]/div/div['+str(r)+']/div/div/div/div[2]/div[2]/div/div[3]/div').text
# status = driver.find_element("xpath",'/html/body/div[1]/div/section[3]/section[1]/div[1]/div/div/div[1]/div/div['+str(r)+']/div/div/div/div[2]/div[2]/div/div[3]/div').text
print(time1)
Data={ 'Time': time1,
'Title': title,
'Available': available}
datalist.append(Data)
df = pd.DataFrame(datalist)
r += 1
print("scraping success!!!")
# if there are no more table data to scrape
except NoSuchElementException:
print("I have some problems -------------------------------")
break
# saving the dataframe to a csv
df.to_csv('table.csv', index=False)
def next_scrap():
counts = 2
while(counts<14):
# driver.get('https://checkout.xola.com/index.html?xwm=eyJvcmlnaW4iOiJodHRwczovL2JvaXNlLnB1enpsZWVmZmVjdC5jb20iLCJjaGFubmVsIjoiRmJyd2syd2ZxVnFIRHNhTSJ9&canSendPII=false&popup=false&embeddedCheckout=true&xdm=true&gaPage=%2Fbook-now%2F&gaCode=UA-115829360-2&gaClient=482825549.1675815012&xb_session_seller_website=boise.puzzleeffect.com&xb_session_user_id=63e423d2729469a8daacccbb&xb_session_session_id=63e423d2729469a8daacccbc&xdm_e=https%3A%2F%2Fboise.puzzleeffect.com&xdm_c=default8725&xdm_p=1#buttons/5cba1a789806c5082936aca8')
driver.find_element("xpath", '//*[@id="header"]/div/div[3]/div/button[2]').click()
print("new scraping", counts)
driver.implicitly_wait(10)
week_scrap()
counts += 1
# driver.close()
if __name__=="__main__":
run()