-
Notifications
You must be signed in to change notification settings - Fork 0
/
url_parser
147 lines (124 loc) · 5.9 KB
/
url_parser
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
import time
import allure
import requests
from selenium import webdriver
from selenium.webdriver import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.wait import WebDriverWait
from PIL import Image, ImageDraw, ImageChops
import httplib2
from selenium.common.exceptions import NoSuchElementException, TimeoutException
from play_polbox import wait_of_element, login_play_polbox, logout_play_polbox, check_url, channel_listing, name_compare, text_recognition, remove_movie, remove_tv, url_categories
def posters_url_checker(driver):
iBrokenImageCount = 0
posters_url = []
time.sleep(5)
image_list = driver.find_elements(By.TAG_NAME, "img")
print('Total number of images are ' + str(len(image_list)))
for img in image_list:
try:
response = requests.get(img.get_attribute('src'), stream=True)
if (response.status_code == 200): # != 200):
image_address = img.get_attribute("src")
web_address = image_address.split('/')
last_part = web_address.pop(-1)[5:]
second_part = web_address.pop(-1)
server_name = web_address.pop(-2)
begin_address = 'http://online.polbox.tv/'
full_address = begin_address + server_name + '/' + second_part + '/' + last_part
posters_url.append(full_address)
except requests.exceptions.MissingSchema:
print("Encountered MissingSchema Exception")
posters_url.pop(0)
return posters_url
def categori_movie(xpath_id, driver):
movie_button = wait_of_element(xpath="//button[text()='Movies']", driver=driver).click()
catalog_items_more = WebDriverWait(driver, 10).until(
EC.visibility_of_element_located((By.XPATH, xpath_id)))
webdriver.ActionChains(driver).move_to_element(catalog_items_more).perform()
animation_movie = wait_of_element(xpath=xpath_id, driver=driver).click()
return
def scroll_page(driver):
i = 20 # листает страницу вниз working
while i < 15000:
try:
xpath_id = '//*[@id="root"]//div[' + str(i) + ']'
catalog_items_more = WebDriverWait(driver, 10).until(EC.visibility_of_element_located((By.XPATH, xpath_id)))
webdriver.ActionChains(driver).move_to_element(catalog_items_more).perform()
i = i + 10
time.sleep(1)
except TimeoutException:
break
return
def poster_size(driver):
for i in posters_url_checker(driver=driver): # проверка постеров на размер менее 500
#small_size = i
try:
response = requests.get(i)
if (response.status_code == 200):
h = httplib2.Http('.cache')
response, content = h.request(i)
out = open('img.png', 'wb')
out.write(content)
out.close()
im = Image.open('img.png')
w, h = im.size
if w < 500:
print(i)
else:
continue
except requests.exceptions.MissingSchema:
print("Encountered MissingSchema Exception")
return
@allure.epic('Testing Play.PolBox.TV')
@allure.feature('Test movie posters size')
@allure.story('Тестирование постеров кинофильмов на маленькое разрешение')
@allure.severity('critical')
def test_posters_size_checker():
#region Browser settings
options = webdriver.ChromeOptions()
prefs = {"profile.default_content_setting_values.notifications": 2}
options.add_experimental_option("prefs", prefs)
options.add_argument(f"--user-data-dir=C:/Users/RMO/AppData/Local/Google/Chrome/User Data")
options.add_argument("javascript.enabled")
#options.headless = True
driver = webdriver.Chrome(options=options, executable_path=r'D:/Selenium/chromedriver.exe')
#endregion
URL = "http://play.polbox.tv/#/"
driver.get(URL)
login_play_polbox('12452341', '242195', driver=driver)
for i in url_categories:
categori_movie(i, driver=driver)
scroll_page(driver=driver)
poster_size(driver=driver)
logout_play_polbox(driver=driver)
driver.quit()
if __name__ == '__main__':
test_posters_size_checker()
film_categories = { "(//button[text()='Show all'])[3]": "Animowany",
"(//button[text()='Show all'])[4]": "Biograficzny",
"(//button[text()='Show all'])[5]": "Dokumentalny",
"(//button[text()='Show all'])[6]": "Dramat",
"(//button[text()='Show all'])[7]": "Familijny",
"(//button[text()='Show all'])[8]": "Fantastyczny",
"(//button[text()='Show all'])[9]": "Historyczny",
"(//button[text()='Show all'])[10]": "Horror",
"(//button[text()='Show all'])[11]": "Kino Akcji",
"(//button[text()='Show all'])[12]": "Komedia",
"(//button[text()='Show all'])[13]": "Kryminalny",
"(//button[text()='Show all'])[14]": "Melodramat",
"(//button[text()='Show all'])[15]": "Muzyczny",
"(//button[text()='Show all'])[16]": "Przygodowy",
"(//button[text()='Show all'])[17]": "Serial",
"(//button[text()='Show all'])[18]": "Sportowy",
"(//button[text()='Show all'])[19]": "Thriller",
"(//button[text()='Show all'])[20]": "Western",
"(//button[text()='Show all'])[21]": "Wojenny"}
movies_butt = wait_of_element(xpath="//button[text()='Movies']", driver=driver).click()
i = 1
for i in film_categories:
movie_butt = wait_of_element(xpath=i, driver=driver)
#categori_name = film_categories.values(i)
i = int(i) + 1
print(i)