-
Notifications
You must be signed in to change notification settings - Fork 1
/
get-urls.py
71 lines (43 loc) · 1.72 KB
/
get-urls.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
import logging
from datetime import datetime
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import TimeoutException
import sys
import time
logging.basicConfig(level=logging.INFO,format='%(asctime)-15s-%(levelname)s:%(pathname)s:%(lineno)s %(message)s')
logger=logging.getLogger()
logger.info("start")
CHROME_DRIVER_PATH="/home/yigit/Downloads/chromedriver"
FIREFOX_DRIVER_PATH="/home/yigit/Downloads/geckodriver"
##option = webdriver.ChromeOptions()
##option.add_argument(" — incognito")
#browser = webdriver.Chrome(executable_path=CHROME_DRIVER_PATH,chrome_options=option)
browser = webdriver.Firefox(executable_path=FIREFOX_DRIVER_PATH)
isQuery= True if "?" in sys.argv[1] else False
page=0
urlsArr=[]
lastPageHit=False
dateTag=datetime.now().strftime("%Y%m%d_%H%M%S")
with open("output/urls_"+dateTag+".out","a") as urls:
while True:
if lastPageHit:
break
page=page + 1
pageStr="&sayfa="+str(page) if isQuery else "?sayfa="+str(page)
browser.get(sys.argv[1]+pageStr)
time.sleep(10)
print("done with sleeping")
all_product_as=browser.find_elements_by_xpath('//div[@class="box product no-hover" or @class="box product"]/a')
print(len(all_product_as))
for a in all_product_as:
if a.get_attribute("href") in urlsArr:
lastPageHit=True
break
print(a.get_attribute("href"))
urls.write(a.get_attribute("href")+"\n")
urlsArr.append(a.get_attribute("href"))
browser.quit()
sys.exit(0)