-
Notifications
You must be signed in to change notification settings - Fork 0
/
Individual_download.py
85 lines (70 loc) · 3.06 KB
/
Individual_download.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
import cv2
import urllib.request as urllib
import numpy as np
from selenium import webdriver
import os
import time
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
driver = webdriver.Chrome()
driver.get('https://www.edmunds.com/alfa-romeo/stelvio/2018/suv/')
first_click32 = driver.find_element_by_xpath(
'/html/body/div[1]/div/main/div[3]/div/div[1]/div/div[1]/div[2]/div/button/img').click()
time.sleep(2)
try:
get_data = driver.find_element_by_xpath(
'/html/body/div[5]/div/div[1]/div/div/div/div/div[2]/div/div/div[1]/div/div[2]/div[2]/div[1]/p').text
print(get_data)
print(type(get_data))
getdata = get_data.split()
gkam = int(getdata[3])
print(gkam)
except:
print("Unable to find integer")
# -----------------------------------------------------------------download Code--------------------------------------------
tt = 1
if gkam > 100:
gkam = 50
while tt < gkam:
try:
img = driver.find_element_by_xpath(
'/html/body/div[5]/div/div[1]/div/div/div/div/div[2]/div/div/div[1]/div/div[2]/div[1]/div/div[1]/img')
src = img.get_attribute('src')
url = src
tag = os.getcwd() + "/car " + str(tt) + ".jpg"
if not os.path.exists(tag):
req = urllib.urlopen(url)
arr = np.asarray(bytearray(req.read()), dtype=np.uint8)
img = cv2.imdecode(arr, -1) # 'Load it as it is'
# cv2.imshow('lalala', img)
try:
location = os.getcwd() + "/" + str(tt) + " car.jpg"
cv2.imwrite(location, img)
except:
print("bound error")
try:
button_path = driver.find_element_by_xpath(
'/html/body/div[5]/div/div[1]/div/div/div/div/div[2]/div/div/div[1]/div/div[2]/div[1]/div/div[1]/div[4]/button').click()
if cv2.waitKey() & 0xff == 27: quit()
except:
print("path not found 1")
button_path = driver.find_element_by_xpath(
"//*[@class='right carousel-control']").click()
else:
print("already exist")
try:
button_path = driver.find_element_by_xpath(
"//*[@class='right carousel-control']").click()
except:
print("path not found 2")
button_path = driver.find_element_by_xpath(
'/html/body/div[5]/div/div[1]/div/div/div/div/div[2]/div/div/div[1]/div/div[2]/div[1]/div/div[1]/div[4]/button').click()
except:
print("error")
try:
button_path = driver.find_element_by_xpath("//*[@class='right carousel-control']").click()
except:
print("path not found 3")
button_path = driver.find_element_by_xpath(
'/html/body/div[5]/div/div[1]/div/div/div/div/div[2]/div/div/div[1]/div/div[2]/div[1]/div/div[1]/div[3]/button').click()
tt = tt + 1