-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlist.py
112 lines (84 loc) · 3.91 KB
/
list.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
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from bs4 import BeautifulSoup
import pandas as pd
import time
driver = webdriver.Chrome()
url = 'https://jkpfactors.com/'
driver.get(url)
time.sleep(3)
# Region/Country
driver.find_element(By.XPATH, '//*[@id="__next"]/div/div[1]/main/div[1]/div/div[1]/div/div/div').click()
data_region = driver.find_elements(By.CLASS_NAME, 'MuiMenuItem-root.MuiMenuItem-gutters.MuiButtonBase-root.css-mli2p5')
time.sleep(1)
list_region = []
for item in data_region:
list_region.append(item.text)
data_region_name = driver.find_elements(By.CLASS_NAME, 'MuiMenuItem-root.MuiMenuItem-gutters.MuiButtonBase-root.css-mli2p5')
list_region_name = []
for item in data_region_name:
list_region_name.append(item.get_attribute('data-value'))
df_region = pd.DataFrame({
'region': list_region,
'query' : list_region_name})
time.sleep(2)
driver.find_element(By.CSS_SELECTOR, '.MuiList-root.MuiList-padding.MuiMenu-list.css-r8u8y9').send_keys(Keys.ESCAPE)
# Theme/Factor
driver.find_element(By.XPATH, '//*[@id="__next"]/div/div[1]/main/div[1]/div/div[2]/div/div/div').click()
data_factor = driver.find_elements(By.CLASS_NAME, 'MuiMenuItem-root.MuiMenuItem-gutters.MuiButtonBase-root.css-mli2p5')
time.sleep(1)
list_factor = []
for item in data_factor:
list_factor.append(item.text)
data_factor_name = driver.find_elements(By.CLASS_NAME, 'MuiMenuItem-root.MuiMenuItem-gutters.MuiButtonBase-root.css-mli2p5')
list_factor_name = []
for item in data_factor_name:
list_factor_name.append(item.get_attribute('data-value'))
df_factor = pd.DataFrame({
'factor': list_factor,
'query' : list_factor_name})
time.sleep(2)
driver.find_element(By.CSS_SELECTOR, '.MuiList-root.MuiList-padding.MuiMenu-list.css-r8u8y9').send_keys(Keys.ESCAPE)
# Frequency
driver.find_element(By.XPATH, '//*[@id="__next"]/div/div[1]/main/div[1]/div/div[3]/div/div/div').click()
data_freq = driver.find_elements(By.CLASS_NAME, 'MuiMenuItem-root.MuiMenuItem-gutters.MuiButtonBase-root.css-mli2p5')
time.sleep(1)
list_freq = []
for item in data_freq:
list_freq.append(item.text)
data_freq_name = driver.find_elements(By.CLASS_NAME, 'MuiMenuItem-root.MuiMenuItem-gutters.MuiButtonBase-root.css-mli2p5')
list_freq_name = []
for item in data_freq_name:
list_freq_name.append(item.get_attribute('data-value'))
df_freq = pd.DataFrame({
'frequency': list_freq,
'query' : list_freq_name})
time.sleep(2)
driver.find_element(By.CSS_SELECTOR, '.MuiList-root.MuiList-padding.MuiMenu-list.css-r8u8y9').send_keys(Keys.ESCAPE)
# Weighting
driver.find_element(By.XPATH, '//*[@id="__next"]/div/div[1]/main/div[1]/div/div[4]/div/div/div').click()
data_wt = driver.find_elements(By.CLASS_NAME, 'MuiMenuItem-root.MuiMenuItem-gutters.MuiButtonBase-root.css-mli2p5')
time.sleep(1)
list_wt = []
for item in data_wt:
list_wt.append(item.text)
data_wt_name = driver.find_elements(By.CLASS_NAME, 'MuiMenuItem-root.MuiMenuItem-gutters.MuiButtonBase-root.css-mli2p5')
list_wt_name = []
for item in data_wt_name:
list_wt_name.append(item.get_attribute('data-value'))
df_wt = pd.DataFrame({
'weight': list_wt,
'query' : list_wt_name})
time.sleep(2)
driver.find_element(By.CSS_SELECTOR, '.MuiList-root.MuiList-padding.MuiMenu-list.css-r8u8y9').send_keys(Keys.ESCAPE)
#--------------#
with pd.ExcelWriter('list.xlsx') as writer:
df_region.to_excel(writer, sheet_name='region', index = False)
df_factor.to_excel(writer, sheet_name='factor', index = False)
df_freq.to_excel(writer, sheet_name='frequency', index = False)
df_wt.to_excel(writer, sheet_name='weight', index = False)