Update scrape/trendyol_scraper_origin.py
Browse files
scrape/trendyol_scraper_origin.py
CHANGED
@@ -32,6 +32,7 @@ def scrape_comments(url):
|
|
32 |
|
33 |
last_height = new_height
|
34 |
|
|
|
35 |
try:
|
36 |
chrome_options = webdriver.ChromeOptions()
|
37 |
chrome_options.add_argument("--disable-notifications")
|
@@ -43,15 +44,24 @@ def scrape_comments(url):
|
|
43 |
chrome_options.add_argument("--start-maximized")
|
44 |
chrome_options.add_argument("user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36")
|
45 |
|
46 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
47 |
driver = webdriver.Chrome(service=service, options=chrome_options)
|
48 |
driver.maximize_window()
|
49 |
|
50 |
driver.get(url)
|
51 |
|
52 |
-
|
53 |
-
|
54 |
-
|
|
|
|
|
|
|
55 |
|
56 |
comprehensive_scroll(driver)
|
57 |
|
@@ -110,7 +120,8 @@ def scrape_comments(url):
|
|
110 |
return None
|
111 |
|
112 |
finally:
|
113 |
-
driver
|
|
|
114 |
|
115 |
if __name__ == "__main__":
|
116 |
# Test URL
|
|
|
32 |
|
33 |
last_height = new_height
|
34 |
|
35 |
+
driver = None
|
36 |
try:
|
37 |
chrome_options = webdriver.ChromeOptions()
|
38 |
chrome_options.add_argument("--disable-notifications")
|
|
|
44 |
chrome_options.add_argument("--start-maximized")
|
45 |
chrome_options.add_argument("user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36")
|
46 |
|
47 |
+
# HuggingFace Spaces için özel ayarlar
|
48 |
+
if os.getenv('SPACE_ID'):
|
49 |
+
chrome_options.binary_location = "/usr/bin/google-chrome"
|
50 |
+
service = ChromeService("/usr/local/bin/chromedriver")
|
51 |
+
else:
|
52 |
+
service = ChromeService(ChromeDriverManager().install())
|
53 |
+
|
54 |
driver = webdriver.Chrome(service=service, options=chrome_options)
|
55 |
driver.maximize_window()
|
56 |
|
57 |
driver.get(url)
|
58 |
|
59 |
+
try:
|
60 |
+
WebDriverWait(driver, 10).until(
|
61 |
+
EC.element_to_be_clickable((By.ID, "onetrust-accept-btn-handler"))
|
62 |
+
).click()
|
63 |
+
except:
|
64 |
+
pass # Bazen cookie popup görünmeyebilir
|
65 |
|
66 |
comprehensive_scroll(driver)
|
67 |
|
|
|
120 |
return None
|
121 |
|
122 |
finally:
|
123 |
+
if driver:
|
124 |
+
driver.quit()
|
125 |
|
126 |
if __name__ == "__main__":
|
127 |
# Test URL
|