-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebConnection.py
42 lines (34 loc) ยท 1.87 KB
/
webConnection.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
from selenium import webdriver
import time
def connectWebDriver(web):
options = webdriver.ChromeOptions()
options.add_argument("disable-gpu")
options.add_argument("headless")
options.add_argument("lang=ko_KR")
# ๋ธ๋ผ์ฐ์ ํ๋ฉด ํฌ๊ธฐ์ ๋ฐ๋ผ ๋ฏธ๋์ด ์ฟผ๋ฆฌ ๋ฑ์ ๋ฐ๋ผ element ๊ตฌ์กฐ๊ฐ
# ๋ฌ๋ผ์ง ์ ์์ผ๋ฏ๋ก ๊ณ ์ ์ํค๊ณ ์์ํ๊ธฐ
options.add_argument('--start-maximized')
options.add_argument(
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.125 Safari/537.36")
driver = webdriver.Chrome('chromedriver/chromedriver', options=options)
# ํค๋ ํ์ง ํผํ๊ธฐ
driver.execute_script("Object.defineProperty(navigator, 'plugins', {get: function() {return[1, 2, 3, 4, 5];},});")
driver.execute_script("Object.defineProperty(navigator, 'languages', {get: function() {return ['ko-KR', 'ko']}})")
driver.execute_script(
"const getParameter = WebGLRenderingContext.getParameter;WebGLRenderingContext.prototype.getParameter = function(parameter) {if (parameter === 37445) {return 'NVIDIA Corporation'} if (parameter === 37446) {return 'NVIDIA GeForce GTX 980 Ti OpenGL Engine';}return getParameter(parameter);};")
driver.implicitly_wait(2)
driver.get(web)
driver.implicitly_wait(2)
return driver
def scrollPage(driver):
SCROLL_PAUSE_TIME = 0.5
last_height = driver.execute_script("return document.body.scrollHeight")
while True:
driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
time.sleep(SCROLL_PAUSE_TIME)
driver.execute_script("window.scrollTo(0, document.body.scrollHeight-50);")
time.sleep(SCROLL_PAUSE_TIME)
new_height = driver.execute_script("return document.body.scrollHeight")
if new_height == last_height:
break
last_height = new_height