added response checking and logging

This commit is contained in:
Brian Bjarke Jensen
2024-03-01 17:09:28 +01:00
parent 7d2afbee4a
commit 878756cded
+6 -5
View File
@@ -3,6 +3,7 @@ from __future__ import annotations
import logging import logging
from selenium import webdriver from selenium import webdriver
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.chrome.service import Service from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.action_chains import ActionChains from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.by import By from selenium.webdriver.common.by import By
@@ -49,7 +50,7 @@ class Instagram:
), ),
) )
logging.debug('located button') logging.debug('located button')
except TimeoutError: except TimeoutException:
logging.error('Timeout before cookie popup appeared.') logging.error('Timeout before cookie popup appeared.')
else: else:
elem.click() elem.click()
@@ -58,18 +59,18 @@ class Instagram:
img_elem_list = self.webdriver.find_elements( img_elem_list = self.webdriver.find_elements(
by=By.XPATH, by=By.XPATH,
value=( value=(
"//article[@role='presentation']" "//*[@role='presentation']"
"//div[@role='presentation']"
"//img[contains(@src,'https://scontent.cdninstagram.com/v/')]" "//img[contains(@src,'https://scontent.cdninstagram.com/v/')]"
), ),
) )
assert len(img_elem_list) > 0
# extract src url # extract src url
img_src_list = [ img_src_list = [
img_elem.get_attribute( img_elem.get_attribute(
'src', name='src',
) for img_elem in img_elem_list ) for img_elem in img_elem_list
] ]
# remove src urls with size mathing profile images # remove src urls with size matching profile images
img_src_list = [ img_src_list = [
img_src for img_src in img_src_list if 's150x150' not in img_src img_src for img_src in img_src_list if 's150x150' not in img_src
] ]