-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathajio_infinite_scroll.py
More file actions
65 lines (43 loc) · 1.71 KB
/
Copy pathajio_infinite_scroll.py
File metadata and controls
65 lines (43 loc) · 1.71 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#file2
#infinite scrolling
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
import time
# This keeps the window open
chrome_options = Options()
chrome_options.add_experimental_option("detach", True)
# --- CAPTCHA BYPASS SETTINGS ---
# This hides the "Automation" flag from Google
chrome_options.add_argument("--disable-blink-features=AutomationControlled")
chrome_options.add_experimental_option("excludeSwitches", ["enable-automation"])
chrome_options.add_experimental_option('useAutomationExtension', False)
# -------------------------------
s = Service(r"C:\Users\rudra\Downloads\chromedriver-win64\chromedriver-win64\chromedriver.exe")
# Pass the options to the driver
driver = webdriver.Chrome(service=s, options=chrome_options)
# Extra script to make the browser look like a normal user
driver.execute_cdp_cmd("Page.addScriptToEvaluateOnNewDocument", {
"source": "Object.defineProperty(navigator, 'webdriver', {get: () => undefined})"
})
driver.get('https://www.ajio.com/men-backpacks/c/830201001')
time.sleep(1)
old_height = driver.execute_script('return document.body.scrollHeight')
time.sleep(2)
counter = 1
while True:
driver.execute_script('window.scrollTo(0,document.body.scrollHeight)')
time.sleep(5)
new_height = driver.execute_script('return document.body.scrollHeight')
print(counter)
counter += 1
print(old_height)
print(new_height)
if new_height == old_height:
break
old_height = new_height
html = driver.page_source
with open('ajio.html','w',encoding='utf-8') as f:
f.write(html)