def bosch(report_lab, page_address, model): driver.get(page_address) sleep(3) # po wczytaniu strona jest przez krótką chwilę zakryta przez inne okno driver.implicitly_wait(3) """ OBRAZKI PRODUKTU """ i = 1 first = '' while True: try: img = driver.find_element_by_xpath(f'//div[@class="slick-track"]/*[{i}]//picture/img').get_attribute( 'src').replace('/600x337', '/1200x675') print(img) if i == 1: first = img else: if first == img: break prod_img(f'{file_path}/{model}', img, i+1) i += 1 except NoSuchElementException: break """OPIS KRÓTKI""" try: shorts = driver.find_element_by_xpath('//div[contains(@class, "morecontent")]//ul').text.split('\n') for i in range(len(shorts)): shorts[i] = '<li>' + shorts[i][:shorts[i].find(':')] + '</li>' short = '<ul>' + ''.join(shorts) + '</ul>' except NoSuchElementException: short = '' print('NoSuchElementException. Brak opisu krótkiego') """OPIS GRAFICZNY""" desc = '' i = 1 while True: print(f'g_desc: {i}') try: text = driver.find_element_by_xpath(f'//*[@id="section-highlights"]/*[{i}]').text try: while True: img = driver.find_element_by_xpath( f'//*[@id="section-highlights"]/*[{i}]//picture//img').get_attribute( "src") driver.find_element_by_xpath( f'//*[@id="section-highlights"]/*[{i}]//picture//img').location_once_scrolled_into_view if i == 2: sleep(2) img = driver.find_element_by_xpath( f'//*[@id="section-highlights"]/*[{i}]//picture//img').get_attribute("src") else: pass if 'Feature_Icons' in img: try: img = driver.find_element_by_xpath( f'//*[@id="section-highlights"]/*[{i}]//div[contains(@class, "mediagallery-slide")][2]//picture//img').get_attribute( "src") except NoSuchElementException: pass replacements = ['/600x337', '/600x'] for replacement in replacements: img = img.replace(replacement, '') res = requests.get(img) with open(f'{file_path}/{model}/obrazki_opisu/{i}.jpg', 'wb') as file_format: file_format.write(res.content) im = Image.open(f'{file_path}/{model}/obrazki_opisu/{i}.jpg') width, height = im.size if width > 480: ratio = width / 480 new_width = round(width / ratio) new_height = round(height / ratio) im = im.resize((new_width, new_height)) try: im.save(f'{file_path}/{model}/obrazki_opisu/{i}.jpg') except OSError: im = im.convert('RGB') im.save(f'{file_path}/{model}/obrazki_opisu/{i}.jpg') break except NoSuchElementException: pass i += 1 if text == '': continue replacements = ['Poprzednie', 'Następne', '1/2', '2/2', '1/3', '2/3', '3/3', 'Dowiedz się więcej', ' Powrót', 'Dalej'] for replacement in replacements: text = text.replace(replacement, '') text = text.split('\n') text = [e for e in text if e] direction = 'left' if i % 2 == 0 else 'right' # tekst po lewej/prawej stronie względem zdjęcia if len(text) == 1: print('jeden') desc += f'<div><h1 class="important-header" style="text-align: center;">{text[0]}</h1></div>' elif len(text) == 2: print('dwa') desc += f"""<div class="two-col-asymmetrically"><div class="{direction}-side"><h2 class="important-header"> {text[0]}</h2> <p style="font-size: large;">{text[1]}</p></div> <img alt="" src="https://matrixmedia.pl/media/wysiwyg/Bosch/{model}/{i}.jpg" /></div> """ elif len(text) == 3: print('trzy') desc += f"""<div class="two-col-asymmetrically"><div class="{direction}-side"><h2 class="important-header"> {text[0]}</h2> <p style="font-size: large;">{text[1]} <br/><br/> <small>{text[2]}</small></p></div> <img alt="" src="https://matrixmedia.pl/media/wysiwyg/Bosch/{model}/{i}.jpg" /></div> """ else: print(f'\n------\n{text}\n------\n') except NoSuchElementException: break desc = '<div class="product-description-section">' + desc + '</div>' """OPIS TECHNICZNY""" driver.get(page_address + '#/Tabs=section-technicalspecs/') driver.find_element_by_xpath('//div[@id="tech-data"]//span[contains(text(), "Specyfikacja techniczna")]').click() # znajdź który div zawiera informacje techniczne i = 1 while True: if 'specyfikacja techniczna' in driver.find_element_by_xpath(f'//div[@id="tech-data"]/*[{i}]').text.lower(): break else: i += 1 # zbierz dane techniczne j = 1 tech = [] driver.implicitly_wait(0.5) while True: try: driver.find_element_by_xpath(f'//div[@id="tech-data"]/*[{i}]/section/div[{j}]/a').click() sleep(0.5) category_name = driver.find_element_by_xpath(f'//div[@id="tech-data"]/*[{i}]/section/div[{j}]/a').text tech.append(f'<tr class="specs_category"><td colspan="2">{category_name}</td></tr>') except NoSuchElementException: break k = 1 while True: try: name = driver.find_element_by_xpath(f'//div[@id="tech-data"]/*[{i}]/section/div[{j}]//tr[{k}]/th').text value = driver.find_element_by_xpath(f'//div[@id="tech-data"]/*[{i}]/section/div[{j}]//tr[{k}]/td').text if value == '': icon = driver.find_element_by_xpath( f'//div[@id="tech-data"]/*[{i}]/section/div[{j}]//tr[{k}]/td').get_attribute('class') value = 'Tak' if icon.lower() == 'checked' else 'Nie' tech.append(f'<tr><td class="c_left">{name}</td><td class="c_left">{value}</td></tr>') k += 1 except NoSuchElementException: break j += 1 tech = ['<table id="plan_b" class="data-table"><tbody>'] + tech + ['</tbody></table>'] tech = ''.join(tech) return [desc, short, tech]
def go(): for data in data_list: driver.implicitly_wait(3) driver.find_element_by_xpath('//input[@name="sku"]').clear() driver.find_element_by_xpath('//input[@name="sku"]').send_keys(data) driver.find_element_by_xpath('//button[@title="Szukaj"]').click() try: x = driver.find_element_by_xpath('//*[@id="messages"]/ul//span').text except NoSuchElementException: x = '' if x == 'Produkt został zapisany.': sleep(2) pyautogui.click(300, 605) else: pyautogui.click(300, 552) try: model = driver.find_element_by_xpath('//*[@id="content"]/div/div[2]/h3').get_attribute("innerText") except NoSuchElementException: undone.append(data) continue model = model[model.find('AMICA')+6:model.find('(')-1] driver.execute_script('''window.open("about:blank", "_blank");''') driver.switch_to.window(driver.window_handles[1]) driver.get(f'https://www.ceneo.pl/;szukaj-{model}?nocatnarrow=1') ceneo_name = driver.find_element_by_xpath('//div[@class="cat-prod-row__desc"]//a').text mod = model.replace(" ", "") ceneo_name = ceneo_name.replace(" ", "") print(f'Model: {mod.lower()} -- Ceneo: {ceneo_name.lower()}) -- {mod.lower() in ceneo_name.lower()}') if mod.lower() in ceneo_name.lower(): link = driver.find_element_by_xpath('//div[@class="cat-prod-row__desc"]//a').get_attribute('href') driver.execute_script("window.close('');") driver.switch_to.window(driver.window_handles[0]) driver.find_element_by_name('product[link_ceneo]').clear() driver.find_element_by_name('product[link_ceneo]').send_keys(link) driver.find_element_by_xpath('//button[@title="Zapisz"]').click() done.append(model) else: driver.execute_script("window.close('');") driver.switch_to.window(driver.window_handles[0]) driver.find_element_by_xpath('//button[@title="Powrót"]').click() undone.append(model) print('Zrobione:') print('\n'.join(done)) print(f'\n\nNiezrobione:') print('\n'.join(undone)) done.clear() undone.clear() data_list.clear()
def go(): for data in data_list: driver.implicitly_wait(1.5) driver.find_element_by_xpath('//input[@name="sku"]').clear() driver.find_element_by_xpath('//input[@name="sku"]').send_keys(data[0]) driver.find_element_by_xpath('//button[@title="Szukaj"]').click() try: x = driver.find_element_by_xpath('//*[@id="messages"]/ul//span').text except NoSuchElementException: x = '' if x == 'Produkt został zapisany.': sleep(2) pyautogui.click(300, 605) else: pyautogui.click(300, 552) try: driver.find_element_by_xpath('//*[@id="content"]/div/div[2]/h3').get_attribute("innerText") except NoSuchElementException: undone.append(data[0]) continue driver.find_element_by_xpath('//input[@name="product[search_keywords]"]').send_keys(' #PrezentGalaxyBuds') driver.find_element_by_xpath('//button[@title="Zapisz"]').click() print(f'\n\nNiezrobione:') print('\n'.join(undone)) done.clear() undone.clear() data_list.clear()
def insert_data(report_label, product, model=None, descriptions=None, brand=None): folder_name = model set_images = False # parametr służący w przyszłości do wybierania czy algorytm ma dodawać zdjęcia opisu do bazy if descriptions is None: descriptions = [1, '', ''] try: driver.find_element_by_css_selector( 'td.a-right button').click() # Dodaj produkt except NoSuchElementException: pass db = mysql.connector.connect(host="localhost", user="******", database="test") cursor = db.cursor() cursor.execute("SELECT * FROM attributes_sets") db_results = cursor.fetchall() results = [] for i in range(len(db_results)): results.append(list(db_results[i])) for j in range(len(results[i])): if results[i][j] is None: results[i][j] = '' attr_set = '' # szukanie zestawu cech for i in range(len(results)): if results[i][1].lower() in product[1].lower( ) and 'zabudo' in product[6].lower(): attr_set = results[i][4] weight = str(results[i][3]) if weight == '': weight = '1' break elif results[i][1].lower() in product[1].lower(): attr_set = results[i][2] weight = str(results[i][3]) if weight == '': weight = '1' break else: weight = '1' try: # zaznaczanie zestawu cech driver.find_element_by_xpath( f'//*[@id="attribute_set_id"]/option[text()="{attr_set}"]').click( ) except NoSuchElementException: print( f'Nie znaleziono zestawu cech. Zrób to ręcznie i wciśnij Enter ({product[1]})\n' ) wait('enter') driver.find_element_by_css_selector( 'button[title="Kontynuuj"]').click() # Konunuuj driver.implicitly_wait( 3 ) # Zawsze czekaj 3 sekundy przed wyświetleniem błędu na wczytanie elementów strony driver.find_element_by_name('product[name]').send_keys( product[1]) # umieść nazwę produktu # umieść opis graficzny driver.find_element_by_name('product[description]').send_keys( descriptions[0]) # jeżeli nie ma opisu, to nie ma też grafik if set_images: try: driver.find_element_by_xpath( '(//button[@title="Edytor WYSIEYG"])[1]').click( ) # kliknij na edytor WYSIEYG if folder_name is not None: driver.find_element_by_xpath( '/html/body/div[2]/table[2]/tbody/tr/td[2]/div/div[' '1]/div/span/div/span/table/tbody/tr[1]/td/div/span/table[2]/tbody/tr/td[' '24]/a/span[1]').click() # kliknij na "Wstawianie obrazka" sleep(1) # poczekaj sekundę, aż wczyta się okno pyautogui.click( 1135, 470 ) # kliknij na "Browse" (nie znalazłem lepszego sposobu) sleep( 7 ) # poczekaj 7 sekund (+ ew. 3 sekundy z metody "implicitly_wait") na wczytanie treści try: driver.find_element_by_xpath( f'//a/span[text()="{brand}"]').click( ) # wybierz folder z nazwą marki driver.find_element_by_xpath( f'//a/span[text()="{brand}"]').click( ) # wybierz folder z nazwą marki except ElementNotInteractableException: print("Spróbuj ponownie (enter)") wait('Enter') driver.find_element_by_xpath( f'//a/span[text()="{brand}"]').click() driver.find_element_by_xpath( f'//a/span[text()="{brand}"]').click() sleep(3) try: driver.find_element_by_xpath( '/html/body/div[1]/table[2]/tbody/tr/td[2]/div/div/div/div/div/div/div[' '2]/div/div[2]/table/tbody/tr/td[2]/button[1]').click( ) # Utwórz folder sleep(1) pyautogui.click( 900, 160 ) # ustaw focus na oknie do wpisywania nazwy folderu pyautogui.typewrite(folder_name) # wprowadź nazwę folderu pyautogui.press('Enter') # zatwierdź enterem sleep(12) driver.find_element_by_xpath( f'//a/span[text()="{folder_name}"]').click( ) # kliknij na nazwę folderu sleep(2) pyautogui.press('Home') # wróć na górę sleep(2) pyautogui.click(900, 290) # kliknij na "Choose files" pyautogui.click(900, 305) # drugi dla pewności sleep(2.5) # poczekaj na załadownie okna pyautogui.hotkey( 'ctrl', 'l') # Ctrl + L (przejdź do adresu folderu) # wprowadź ścieżkę folderu z obrazkami do opisu pyautogui.typewrite( f'C:/Users/user/PycharmProjects/Adding-automating-products/Imgs/{folder_name}/obrazki_opisu' ) pyautogui.press('enter') # zatwierdź enterem sleep(2) pyautogui.click(300, 300) pyautogui.hotkey('ctrl', 'a') # Ctrl + A (zaznacz wszystko) pyautogui.press('enter') # zatwierdź Enterem pyautogui.press('Home') # wróć na górę sleep(7) except UnexpectedAlertPresentException: report_label[ 'text'] += f'Produkt {product[1]} już jest dodany.\n' pyautogui.click(1150, 180) except NoSuchElementException: pass finally: try: driver.find_element_by_xpath('//*[@id="browser_window_close"]' ).click() # zamknij jedno okno driver.find_element_by_xpath('/html/body/div[6]/div/a[5]' ).click() # zamknij drugie okno driver.find_element_by_xpath('//button[@title="Submit"]' ).click() # zamknij trzecie okno except NoSuchElementException: pass driver.find_element_by_name('product[short_description]').send_keys( descriptions[1]) # wprowadź krótki opis if not descriptions[1] == '': try: driver.find_element_by_xpath( '(//button[@title="Edytor WYSIEYG"])[2]').click( ) # otwórz edytor WYSIEYG # zamknij edytory WYSIEYG (żeby sformatować tekst) driver.find_element_by_xpath('//button[@title="Submit"]').click() except NoSuchElementException: print( "Otwórz Edytor WYSIEYG dla opisu krótkiego, zatwierdź i wciśnij Enter" ) wait('Enter') driver.find_element_by_name('product[sku]').send_keys( product[2]) # wprowadzenie Eanu driver.find_element_by_name('product[weight]').send_keys( weight) # wprowadzenie wagi driver.find_element_by_xpath( '//*[@id="status"]/option[3]').click() # status: Nieaktywny # jeżeli marka jest znana - zaznacz ją if brand != 'nie wykryto': try: driver.find_element_by_xpath( f'//*[@id="manufacturer"]/option[text()="{brand}"]').click() except NoSuchElementException: try: driver.find_element_by_xpath( f'//*[@id="manufacturer"]/option[text()="{brand.upper()}"]' ).click() except NoSuchElementException: pass driver.find_element_by_name('product[url_key]').send_keys( product[1]) # wprowadzenie klucza url driver.find_element_by_name('product[manufacturer_code]').send_keys( product[0]) # wprowadzenie klucza producenta # znajdź link do aukcji ceneo driver.execute_script('''window.open("about:blank", "_blank");''') driver.switch_to.window(driver.window_handles[1]) driver.get(f'https://www.ceneo.pl/;szukaj-{model}?nocatnarrow=1') try: ceneo_name = driver.find_element_by_xpath( '//div[@class="cat-prod-row__desc"]//a').text # weź tylko litery z dwóch nazw modeli (ceneo_name oraz mod) buffor = '' for i in range(len(ceneo_name)): if ceneo_name[i].isalpha(): buffor += ceneo_name[i] ceneo_name = buffor mod = '' for i in range(len(model)): if model[i].isalpha(): mod += model[i] # sprawdzenie ręczne czy analiza jest poprawna print( f'Model: {mod.lower()} -- Ceneo: {ceneo_name.lower()} -- {mod.lower() in ceneo_name.lower()}' ) if mod.lower() in ceneo_name.lower(): link = driver.find_element_by_xpath( '//div[@class="cat-prod-row__desc"]//a').get_attribute('href') driver.execute_script("window.close('');") driver.switch_to.window(driver.window_handles[0]) driver.find_element_by_name('product[link_ceneo]').send_keys(link) else: driver.execute_script("window.close('');") driver.switch_to.window(driver.window_handles[0]) except NoSuchElementException: driver.execute_script("window.close('');") driver.switch_to.window(driver.window_handles[0]) driver.find_element_by_name('product[tech_description]').send_keys( descriptions[2]) # wprowadź opis techniczny if not descriptions[2] == '': driver.find_element_by_xpath('(//button[@title="Edytor WYSIEYG"])[3]' ).click() # otwórz edytor WYSIEYG driver.find_element_by_xpath( '//button[@title="Submit"]').click() # zamknij edytor WYSIEYG # zazancz centralę w punktach odbioru try: driver.find_element_by_xpath( f'//*[@id="pickup_store"]/option[1]').click() except NoSuchElementException: pass if 'sony' in product[1].lower(): sony_rec = [2, 3, 4, 7, 8, 9, 10, 11, 21, 25] for ele in sony_rec: driver.find_element_by_xpath( f'//*[@id="pickup_store"]/option[{ele}]').click() if 'samsung' in product[1].lower(): samsing_rec = [5, 6, 12, 13, 14, 15, 16, 17, 18, 19, 20, 23] for ele in samsing_rec: driver.find_element_by_xpath( f'//*[@id="pickup_store"]/option[{ele}]').click() if 'huawei' in product[1].lower(): huawei_rec = [24] for ele in huawei_rec: driver.find_element_by_xpath( f'//*[@id="pickup_store"]/option[{ele}]').click() # wyłącz Huaweia z negocjacji cen driver.find_element_by_xpath( '//select[@name="product[price_negotiation_hide]"]/option[1]' ).click() # podobno nie są już potrzebne, więc zakomentowałem, ale zostawiam w razie W # driver.find_element_by_name('product[search_keywords]').send_keys(f'{product[1]} {product[2]}') # słowa kluczowe # Ceny driver.find_element_by_tag_name('body').send_keys( Keys.HOME ) # powrót na górę strony, aby można było odnaleźć szukane elementy sleep(0.5) # poczekaj na działanie klawisza Home driver.find_element_by_css_selector( 'a[title="Ceny"]').click() # przejdź do zakładki "Ceny" driver.find_element_by_name('product[price]').send_keys( '9999,99') # wprowadź domyślną cenę 9999,99 driver.find_element_by_css_selector( '#tax_class_id > option:nth-child(2)').click() # Klasa podatku: Brak # Matrix Media driver.find_element_by_css_selector('a[title="Matrix Media"]').click( ) # przejdź do zakładki "Matrix Media" # jeżeli reguła i priorytet nadawcy są poprawnie wpisane, to zaznacz je try: driver.find_element_by_xpath( f'//*[@id="rule"]/option[text()="{product[4]}"]').click() except NoSuchElementException: report_label['text'] += "Błędnie wpisana reguła\n" try: driver.find_element_by_xpath( f'//*[@id="supplier"]/option[text()="{product[5]}"]').click() except NoSuchElementException: report_label['text'] += "Błędnie wpisany dostawca\n" # Porównywarki cenowe driver.find_element_by_css_selector( 'a[title="Porównywarki cenowe"]').click() driver.find_element_by_xpath('//*[@id="export_ceneo"]/option[1]').click() # Kategorie driver.find_element_by_css_selector('a[title="Kategorie"]').click() categories(product[1], product[6], attr_set) # Zbyt rozległe, żeby to zostawiać tutaj # Zestaw cech try: driver.find_element_by_css_selector(f'a[title="{attr_set}"]').click() attributes(descriptions[2], brand) except NoSuchElementException: pass # Obrazki produktu driver.find_element_by_css_selector('a[title="Obrazki produktu"]').click() # jeżeli nie ma opisu, to nie ma też grafik if not descriptions[0] == 1: driver.find_element_by_tag_name('body').send_keys( Keys.HOME ) # powrót na górę strony, aby można było odnaleźć szukane elementy sleep(2) pyautogui.click(500, 570) pyautogui.click(500, 620) pyautogui.click(500, 650) # trzy razy dla pewności, bo bywało różnie sleep(2) pyautogui.hotkey('ctrl', 'l') # Ctrl + L pyautogui.keyUp('ctrl') pyautogui.keyUp('l') # puszczenie Ctrl + L # wprowadzenie ścieżki gdzie znajdują się obrazki produktu pyautogui.typewrite( f'C:/Users/user/PycharmProjects/Adding-automating-products/Imgs/{folder_name}/obrazki_produktu' ) pyautogui.press('enter') # Enter sleep(0.5) pyautogui.click(300, 300) pyautogui.hotkey('ctrl', 'a') # Ctrl + A pyautogui.press('enter') # Enter sleep(1) sleep(2) driver.find_element_by_css_selector( 'button[title="Zapisz i kontynuuj edycję"]').click() # Zapisz wait('enter') sleep(3) driver.find_element_by_css_selector( 'button[title="Zapisz"]').click() # Zapisz sleep(3) report_label['text'] += f'Dodano {product[1]}\n'
def categories(name, parameter, attr_set): name = name.lower() parameter = parameter.lower() # TV i Audio if 'Telewizory' in attr_set or 'Słuchawki' in attr_set: driver.find_element_by_xpath( '//div[contains(@class, "x-tree-node")]//span[contains(text(), "TV i Audio")]' ).click() if 'Telewizory' in attr_set: # Telewizory driver.find_element_by_xpath( '//div[contains(@class, "x-tree-node")]//span[contains(text(), "Telewizory")]' ).click() if 'Słuchawki' in attr_set: # Słuchawki driver.find_element_by_xpath( '//div[contains(@class, "x-tree-node")]//span[contains(text(), "Słuchawki")]' ).click() # AGD if 'wolnost' in parameter or 'zabudo' in parameter: driver.find_element_by_xpath( '//div[contains(@class, "x-tree-node")]//span[contains(text(), "AGD")]' ).click() if 'wolnost' in parameter: # Wolnostojące driver.find_element_by_xpath( '//div[contains(@class, "x-tree-node")]//span[contains(text(), "Wolnostojące")]' ).click() if 'Pralki' in attr_set: # Pralki driver.find_element_by_xpath( '//div[contains(@class, "x-tree-node")]//span[contains(text(), "Pralki")]' ).click() if 'Suszarki' in attr_set: # Suszarki driver.find_element_by_xpath( '//div[contains(@class, "x-tree-node")]//span[contains(text(), "Suszarki")]' ).click() if 'Pralko-suszarki' in attr_set: # Pralko-suszarki driver.find_element_by_xpath( '//div[contains(@class, "x-tree-node")]//span[contains(text(), "Pralko-suszarki")]' ).click() if 'Lodówki' in attr_set: # Lodówki driver.find_element_by_xpath( '//div[contains(@class, "x-tree-node")]//span[contains(text(), "Lodówki")]' ).click() if 'Zamrażarki' in attr_set: # Zamrażarki driver.find_element_by_xpath( '//div[contains(@class, "x-tree-node")]//span[contains(text(), "Zamrażarki")]' ).click() if 'Kuchnie wolnostojące > Kuchnie' in attr_set: # Kuchnie wolnostojące driver.find_element_by_xpath( '//div[contains(@class, "x-tree-node")]//span[contains(text(), "Kuchnie wolnostojące")]' ).click() if 'Okapy' in attr_set: # Okapy driver.find_element_by_xpath( '//div[contains(@class, "x-tree-node")]//span[contains(text(), "Okapy")]' ).click() if 'Zmywarki' in attr_set: # Zmywarki driver.find_element_by_xpath( '//div[contains(@class, "x-tree-node")]//span[contains(text(), "Zmywarki")]' ).click() if 'Kuchnie mikrofalowe' in attr_set: # Kuchnie mikrofalowe driver.find_element_by_xpath( '//div[contains(@class, "x-tree-node")]//span[contains(text(), "Kuchnie mikrofalowe")]' ).click() elif 'zabudo' in parameter: # Do zabudowy driver.find_element_by_xpath( '//div[contains(@class, "x-tree-node")]//span[contains(text(), "Do zabudowy")]' ).click() if 'Lodówki do zabudowy' in attr_set: # Lodówki (do zabudowy) driver.find_element_by_xpath( '//div[contains(@class, "x-tree-node")]//span[contains(text(), "Lodówki")]' ).click() if 'Zmywarki' in attr_set: # Zmywarki (do zabudowy) driver.find_element_by_xpath( '//div[contains(@class, "x-tree-node")]//span[contains(text(), "Zmywarki")]' ).click() if 'Piekarniki do zabudowy' in attr_set: # Piekarniki (do zabudowy) driver.find_element_by_xpath( '//div[contains(@class, "x-tree-node")]//span[contains(text(), "Piekarniki")]' ).click() if 'Płyty do zabudowy' in attr_set: # Płyty do zabudowy driver.find_element_by_xpath( '//div[contains(@class, "x-tree-node")]//span[contains(text(), "Płyty")]' ).click() if 'Kuchenki mikrofalowe do zabudowy' in attr_set: # Kuchenki mikrofalowe do zabudowy driver.find_element_by_xpath( '//div[contains(@class, "x-tree-node")]//span[contains(text(), "Kuchenki mikrofalowe")]' ).click() if 'Okapy' in attr_set: # Okapy (do zabudowy) driver.find_element_by_xpath( '//div[contains(@class, "x-tree-node")]//span[contains(text(), "Okapy kuchenne")]' ).click() if 'Ekspresy' in attr_set: # Ekspresy (do zabudowy) driver.find_element_by_xpath( '//div[contains(@class, "x-tree-node")]//span[contains(text(), "Ekspresy")]' ).click() if 'Parownice' in attr_set: # Parowary (do zabudowy) driver.find_element_by_xpath( '//div[contains(@class, "x-tree-node")]//span[contains(text(), "Parowary")]' ).click() else: # Akcesoria AGD driver.find_element_by_xpath( '//div[contains(@class, "x-tree-node")]//span[contains(text(), "Akcesoria AGD")]' ).click() # AGD małe if 'Depilatory' in attr_set or 'Maszynki do strzyżenia' in attr_set: driver.find_element_by_xpath( '//div[contains(@class, "x-tree-node")]//span[contains(text(), "AGD małe")]' ).click() # Sprzątanie # # Kuchnia # if 'Depilatory' in attr_set or 'Maszynki do strzyżenia' in attr_set: # Uroda i zdrowie driver.find_element_by_xpath( '//div[contains(@class, "x-tree-node")]//span[contains(text(), "Uroda i zdrowie")]' ).click() if 'Depilatory' in attr_set or 'Maszynki do strzyżenia' in attr_set: # Golenie i strzyżenie driver.find_element_by_xpath( '//div[contains(@class, "x-tree-node")]//span[contains(text(), "Golenie i strzyżenie")]' ).click() # Lodówki turystyczne # # Smartfony i GPS if 'watch' in name or 'zegarek' in name or 'telefon' in name or 'smartfon' in name or 'smartphone' in name: driver.find_element_by_xpath( '//div[contains(@class, "x-tree-node")]//span[contains(text(), "Smartfony i GPS")]' ).click() # Smartfony if 'smartfon' in name or 'smartphone' in name: driver.find_element_by_xpath( '(//div[contains(@class, "x-tree-node")]//span[contains(text(), "Smartfony")])[2]' ).click() if attr_set == 'Telefony i smartfony > Smartfony z Android': driver.find_element_by_xpath( '//div[contains(@class, "x-tree-node")]//span[contains(text(), "Smartfony z Androidem")]' ).click() if 'watch' in name or 'zegarek' in name: # Smartwatche i Opaski sportowe driver.find_element_by_xpath( '//div[contains(@class, "x-tree-node")]//span[contains(text(), "Smartwatche i Opaski sportowe")]' ).click() # Smarthome # # Akcesoria GSM # if 'do telefonu' in name: driver.find_element_by_xpath( '//div[contains(@class, "x-tree-node")]//span[contains(text(), "Akcesoria GSM")]' ).click() # Akcesoria samochodowe # # Komputery i laptopy if 'Laptopy / Ultrabooki' in attr_set or 'Tablety' in attr_set: driver.find_element_by_xpath( '//div[contains(@class, "x-tree-node")]//span[contains(text(), "Komputery i Laptopy")]' ).click() if 'Tablety' in attr_set: # Tablety driver.find_element_by_xpath( '//div[contains(@class, "x-tree-node")]//span[contains(text(), "Tablety")]' ).click() # AIO # if 'Laptopy / Ultrabooki' in attr_set: # Laptopy / Ultrabooki driver.find_element_by_xpath( '//ul[contains(@class, "x-tree-node-ct")]//span[contains(text(), "Laptopy")]' ).click() # Peryferia if 'Dyski HDD' in attr_set or 'Dyski SSD' in attr_set: driver.find_element_by_xpath( '//div[contains(@class, "x-tree-node")]//span[contains(text(), "Peryferia")]' ).click() if 'Dyski HDD' in attr_set or 'Dyski SSD' in attr_set: # Dyski driver.find_element_by_xpath( '//div[contains(@class, "x-tree-node")]//span[contains(text(), "Dyski")]' ).click() # Akcesoria do komputerów # # Akcesoria do laptopów # # Sport i rekreacja if 'Deskorolki' in attr_set: driver.find_element_by_xpath( '//div[contains(@class, "x-tree-node")]//span[contains(text(), "Sport i rekreacja")]' ).click() # Gaming if 'Gry' in attr_set: driver.find_element_by_xpath( '//div[contains(@class, "x-tree-node")]//span[contains(text(), "Gaming")]' ).click() # Foto i Video # # Lego # # >> Outlet << # # Oferta specjana # # Sony # # Samsung # if 'samsung' in name: driver.find_element_by_xpath( '//div[contains(@class, "x-tree-node")]//span[contains(text(), "Samsung")]' ).click() # Karcher # # Miele # # Apple # # AB # # MORAX # return
def go(): for data in data_list: driver.implicitly_wait(1.5) try: driver.find_element_by_xpath('//input[@name="name"]').clear() driver.find_element_by_xpath('//input[@name="name"]').send_keys( data[0]) except NoSuchElementException: wait('Enter') driver.find_element_by_xpath('//input[@name="name"]').clear() driver.find_element_by_xpath('//input[@name="name"]').send_keys( data[0]) driver.find_element_by_xpath('//button[@title="Szukaj"]').click() sleep(1) try: print( driver.find_element_by_xpath( '//*[@id="productGrid_table"]/tbody/tr/td[7]').text) except NoSuchElementException: print('') undone.append(data[0]) print(f'\n\nNiezrobione:') print('\n'.join(undone)) done.clear() undone.clear() data_list.clear()
def go(): for data in data_list: driver.implicitly_wait(3) driver.find_element_by_xpath('//input[@name="sku"]').clear() driver.find_element_by_xpath('//input[@name="sku"]').send_keys(data[0]) driver.find_element_by_xpath('//button[@title="Szukaj"]').click() try: x = driver.find_element_by_xpath( '//*[@id="messages"]/ul//span').text except NoSuchElementException: x = '' if x == 'Produkt został zapisany.': sleep(2) pyautogui.click(300, 552) else: pyautogui.click(300, 502) try: driver.find_element_by_xpath( '//*[@id="content"]/div/div[2]/h3').get_attribute("innerText") except NoSuchElementException: undone.append(data[0]) continue driver.find_element_by_xpath('//a[@title="Zestawy"]').click() for ean in eans_in_set: sleep(0.5) driver.find_element_by_xpath( '//button[@title="Dodaj nowy zestaw"]').click() driver.find_element_by_xpath( '//div[contains(@id, "bundlediscount_option")][1]//input[@class="input-text"]' ).send_keys(set_name[eans_in_set.index(ean)]) driver.find_element_by_xpath( '//div[contains(@id, "bundlediscount_option")][1]//input[contains(@class, "validate-date-range")][1]' ).send_keys(date_from) driver.find_element_by_xpath( '//div[contains(@id, "bundlediscount_option")][1]//input[contains(@class, "validate-date-range")][2]' ).send_keys(date_to) driver.find_element_by_xpath( '//div[contains(@id, "bundlediscount_option")][1]//input[contains(@name, "[sort_order]")]' ).send_keys(sorting_order) driver.find_element_by_xpath( '//div[contains(@id, "bundlediscount_option")][1]//select[contains(@name, "[customer_groups]")]/option[1]' ).click() driver.find_element_by_xpath( '//div[contains(@id, "bundlediscount_option")][1]//select[contains(@name, "[customer_groups]")]/option[2]' ).click() driver.find_element_by_xpath( '//div[contains(@id, "bundlediscount_option")][1]//select[contains(@name, "[customer_groups]")]/option[3]' ).click() driver.find_element_by_xpath( '//div[contains(@id, "bundlediscount_option")][1]//select[contains(@name, "[customer_groups]")]/option[4]' ).click() driver.find_element_by_xpath( '//div[contains(@id, "bundlediscount_option")][1]//select[contains(@name, "[store_ids]")]/option[1]' ).click() driver.find_element_by_xpath( '//div[contains(@id, "bundlediscount_option")][1]//select[contains(@name, "[store_ids]")]//option[contains(text(), "Default Store View")]' ).click() driver.find_element_by_xpath( '//div[contains(@id, "bundlediscount_option")][1]//button[@title="Dodaj nowy produkt"]' ).click() driver.find_element_by_xpath( '//div[contains(@id, "bundlediscount_option")][1]//input[@name="sku"]' ).send_keys(ean) driver.find_element_by_xpath( '//div[contains(@id, "bundlediscount_option")][1]//button[@title="Szukaj"]' ).click() driver.find_element_by_xpath( '//div[contains(@id, "bundlediscount_option")][1]//tr[@title="#"]' ).click() driver.find_element_by_xpath( '//div[contains(@id, "bundlediscount_option")][1]//button[@title="Dodaj wybrane produkt(y) do opcji"]' ).click() driver.find_element_by_xpath( '//div[contains(@id, "bundlediscount_option")][1]//table[@class="border"]//tr[1]//input[contains(@name, "[discount_price]")]' ).clear() driver.find_element_by_xpath( '//div[contains(@id, "bundlediscount_option")][1]//table[@class="border"]//tr[1]//input[contains(@name, "[discount_price]")]' ).send_keys(promo_price[eans_in_set.index(ean)]) driver.find_element_by_xpath('//button[@title="Zapisz"]').click() done.append(data[0]) print(f'\n\nNiezrobione:') print('\n'.join(undone)) done.clear() undone.clear() data_list.clear()
def go(): for data in data_list: driver.implicitly_wait(1.5) name = 'name' try: driver.find_element_by_xpath(f'//input[@name="{name}"]').clear() driver.find_element_by_xpath(f'//input[@name="{name}"]').send_keys( data[0]) except NoSuchElementException: wait('Enter') driver.find_element_by_xpath(f'//input[@name="{name}"]').clear() driver.find_element_by_xpath(f'//input[@name="{name}"]').send_keys( data[0]) driver.find_element_by_xpath('//button[@title="Szukaj"]').click() sleep(1) i = 1 while True: try: if data[0] in driver.find_element_by_xpath( f'//*[@id="productGrid_table"]/tbody/tr[{i}]/td[3]' ).text: done.append( driver.find_element_by_xpath( f'//*[@id="productGrid_table"]/tbody/tr[{i}]/td[2]' ).text) break i += 1 except NoSuchElementException: undone.append(data[0]) break for i in range(0, len(done), 5): try: step = f'{done[i]}' step += f', {done[i + 1]}' step += f', {done[i + 2]}' step += f', {done[i + 3]}' step += f', {done[i + 4]}' except IndexError: pass print(step) print(f'\n\nNiezrobione:') print('\n'.join(undone)) done.clear() undone.clear() data_list.clear()
def amica(report_label, product, model): from globals import file_path if product[7].startswith('http'): page_address = product[7] driver.get(product[7]) html = requests.get(product[7]).content sel = Selector(text=html) else: search = product[1][product[1].lower().find('amica') + len('amica') + 1:] amica_link = f'https://www.amica.pl/szukaj/{search}' driver.get(amica_link) html = requests.get(amica_link).content sel = Selector(text=html) # Znajdź model na stronie Amica try: for i in range(len(sel.xpath('//div[@class="container"]'))): if driver.find_element_by_xpath( f'//h3[@class="prodSymbol"][{i + 1}]').text == model: page_address = driver.find_element_by_xpath( f'//h3[@class="prodSymbol"][{i + 1}]/a').get_attribute( 'href') break except NoSuchElementException: report_label[ 'text'] += f"Nie znaleziono {model} na stronie Amica. Pomijam go." return -1 driver.find_element_by_css_selector( '#produkty > div.moreProducts > div > div > div > div > div > div > div.image > a' ).click() sleep(1) driver.find_element_by_css_selector( '#menu01 > div > div.product-view__media > img').click() first = driver.find_element_by_css_selector( '#prod_app > div.medialightbox__overlay > div > div.cool-lightbox__inner > div.cool-lightbox__wrapper > ' 'div > div > img').get_attribute('src') # Zapisywanie i obrabianie zdjęc do miniaturek i = 0 while i < 15: if i == 0: res = requests.get(first) else: desc_img = driver.find_element_by_css_selector( '#prod_app > div.medialightbox__overlay > div > div.cool-lightbox__inner > div.cool-lightbox__wrapper ' '> div > div > img').get_attribute('src') if desc_img == first: break res = requests.get(desc_img) with open(f'{file_path}/{model}/obrazki_produktu/{i}.jpg', 'wb') as file_format: file_format.write(res.content) try: driver.find_element_by_xpath( '//*[@id="prod_app"]/div[4]/div/div[2]/div[2]/button[2]/div' ).click() except ElementNotInteractableException: pass sleep(1) i = i + 1 for y in range(i): im = Image.open(f'{file_path}/{model}/obrazki_produktu/{y}.jpg') file_format = im.format width, height = im.size if width > height: ratio = width / 600 else: ratio = height / 600 new_width = round(width / ratio) new_height = round(height / ratio) im = im.resize((new_width, new_height)) if file_format == 'PNG': im.save(f'{file_path}/{model}/obrazki_produktu/{y}.jpg', 'PNG') elif file_format == 'JPEG': im.save(f'{file_path}/{model}/obrazki_produktu/{y}.jpg', 'JPEG') else: print(f"Nie umiem zrobić zdjęcia nr {y} :'( (typ {file_format})") driver.find_element_by_tag_name('body').send_keys(Keys.ESCAPE) html = requests.get(page_address).content sel = Selector(text=html) raw = sel.xpath('/html/body/div[1]/script[4]/text()').extract() for i in range(len(raw)): raw[i] = raw[i].replace('\n', '') raw[i] = raw[i].replace('\t', '') raw[i] = raw[i].replace('\xa0', '') raw[i] = raw[i].replace('\r', '') raw[i] = raw[i].replace(' ', '') t = raw[0] t = t[t.find('"descTitle":'):] t = t[:t.find('}]}')] desc = [] imgs = [] while t.find('"descTitle":') != -1: t = t[t.find('"descTitle":') + 13:] desc.append(t[:t.find('"')]) t = t[t.find('"descIconUrl":') + 15:] imgs.append(t[:t.find('"')]) t = t[t.find('"descText":') + 12:] desc.append(t[:t.find('"')]) for i in range(len(imgs)): imgs[i] = imgs[i].replace('\\', '') # pobieranie zdjęć z opisu na dysk lokalny for i, img in enumerate(imgs): res = requests.get(img) with open(f'{file_path}/{model}/obrazki_opisu/{i}.jpg', 'wb') as file_format: file_format.write(res.content) for i in range(len(desc)): desc[i] = desc[i].replace('\\u0105', 'ą') desc[i] = desc[i].replace('\\u0119', 'ę') desc[i] = desc[i].replace('\\u0107', 'ć') desc[i] = desc[i].replace('\\u0144', 'ń') desc[i] = desc[i].replace('\\u015b', 'ś') desc[i] = desc[i].replace('\\u015a', 'Ś') desc[i] = desc[i].replace('\\u00f3', 'ó') desc[i] = desc[i].replace('\\u0141', 'Ł') desc[i] = desc[i].replace('\\u0142', 'ł') desc[i] = desc[i].replace('\\u017a', 'ź') desc[i] = desc[i].replace('\\u017b', 'Ż') desc[i] = desc[i].replace('\\u017c', 'ż') desc[i] = desc[i].replace('\\u017', 'Ź') desc[i] = desc[i].replace('\\u00ae', '®') desc[i] = desc[i].replace('\\u00b0', '°') desc[i] = desc[i].replace('\u00b0', '°') desc[i] = desc[i].replace('\u2070', '°') desc[i] = desc[i].replace('\\u2070', '°') desc[i] = desc[i].replace('\\u2013', '-') desc[i] = desc[i].replace('\u2013', '-') desc[i] = desc[i].replace('\\u2026', '...') desc[i] = desc[i].replace('\u2026', '...') desc[i] = desc[i].replace('\\n', '') desc[i] = desc[i].replace('\\/', '/') j = 0 fin = ['<div class="product-description-section">'] for i in range(0, len(desc), 6): fin.append('<div class="three-col-equaly">') try: fin.append( f'<div><img src="https://matrixmedia.pl/media/wysiwyg/Amica/' f'{model}/{j}.jpg"/><br/><h2 class="important-header">{desc[i]}</h2>' ) fin.append(f'<p style="font-size: large;">{desc[i + 1]}</p></div>') fin.append( f'<div><img src="https://matrixmedia.pl/media/wysiwyg/Amica/' f'{model}/{j + 1}.jpg"/><br/><h2 class="important-header"> {desc[i + 2]}</h2>' ) fin.append(f'<p style="font-size: large;">{desc[i + 3]}</p></div>') fin.append( f'<div><img src="https://matrixmedia.pl/media/wysiwyg/Amica/' f'{model}/{j + 2}.jpg"/><br/><h2 class="important-header"> {desc[i + 4]}</h2>' ) fin.append(f'<p style="font-size: large;">{desc[i + 5]}</p></div>') except IndexError: pass finally: fin.append('</div>') j = j + 3 fin.append('</div>') reg = ''.join(fin) reg = reg.replace( '*Zdjęcie ma charakter poglądowy i może nie przedstawiać dokładnego modelu produktu.', '') print("------------ OPIS GRAFICZNY ------------") print(reg + '\n\n') """ OPIS TECHNICZNY """ html = requests.get(page_address).content sel = Selector(text=html) tech_raw = sel.xpath('/html/body/div[1]/script[4]/text()').extract() tech_raw2 = tech_raw[0] tech_d = tech_raw2[tech_raw2.find('"attrGroupData"'):tech_raw2. find('"docFilesDataList"')] tech_desc_1 = [] while tech_d.find('"attrName":') != -1: tech_d = tech_d[tech_d.find('"attrName":') + 12:] tech_desc_1.append(tech_d[:tech_d.find('"')]) tech_d = tech_d[tech_d.find('"attrValue":') + 13:] tech_desc_1.append(tech_d[:tech_d.find('"')]) tech_d2 = tech_d[tech_d.find(tech_desc_1[-1]):] tech_desc_2 = [] while tech_d2.find('"attrValue":') != -1: tech_d2 = tech_d2[tech_d2.find('"attrValue":') + 13:] tech_desc_2.append(tech_d2[:tech_d2.find('"')]) tech_desc = [ '<table id="plan_b" class="data-table"><tbody><tr class="specs_category"><td ' 'colspan="2">Specyfikacja</td></tr>' ] for i in range(0, len(tech_desc_1), 2): tech_desc.append(f'<tr><td class="c_left">{tech_desc_1[i]}</td>') tech_desc.append(f'<td class="c_left">{tech_desc_1[i + 1]}</td></tr>') for i in range(len(tech_desc_2)): if i == 0: tech_desc.append(f'<tr><td class="c_left">Funkcje</td>') tech_desc.append(f'<td class="c_left">{tech_desc_2[i]}</td></tr>') else: tech_desc.append(f'<tr><td class="c_left"></td>') tech_desc.append(f'<td class="c_left">{tech_desc_2[i]}</td></tr>') tech_desc.append('</tbody></table>') for i in range(len(tech_desc)): tech_desc[i] = tech_desc[i].replace('\\u0105', 'ą') tech_desc[i] = tech_desc[i].replace('\\u0119', 'ę') tech_desc[i] = tech_desc[i].replace('\\u0107', 'ć') tech_desc[i] = tech_desc[i].replace('\\u0144', 'ń') tech_desc[i] = tech_desc[i].replace('\\u015b', 'ś') tech_desc[i] = tech_desc[i].replace('\\u015a', 'Ś') tech_desc[i] = tech_desc[i].replace('\\u00f3', 'ó') tech_desc[i] = tech_desc[i].replace('\\u0141', 'Ł') tech_desc[i] = tech_desc[i].replace('\\u0142', 'ł') tech_desc[i] = tech_desc[i].replace('\\u017a', 'ź') tech_desc[i] = tech_desc[i].replace('\\u017b', 'Ż') tech_desc[i] = tech_desc[i].replace('\\u017c', 'ż') tech_desc[i] = tech_desc[i].replace('\\u017', 'Ź') tech_desc[i] = tech_desc[i].replace('\\u00ae', '®') tech_desc[i] = tech_desc[i].replace('\\u00b0', '°') tech_desc[i] = tech_desc[i].replace('\u00b0', '°') tech_desc[i] = tech_desc[i].replace('\u2070', '°') tech_desc[i] = tech_desc[i].replace('\\u2070', '°') tech_desc[i] = tech_desc[i].replace('\\u2013', '-') tech_desc[i] = tech_desc[i].replace('\u2013', '-') tech_desc[i] = tech_desc[i].replace('\\u2026', '...') tech_desc[i] = tech_desc[i].replace('\u2026', '...') tech_desc[i] = tech_desc[i].replace('\\n', '') tech_desc[i] = tech_desc[i].replace('\\/', '/') tech_desc[i] = tech_desc[i].replace(':', '') tech = ''.join(tech_desc) print('------------ OPIS TECHNICZNY ------------') print(tech + '\n\n') """ OPIS KRÓTKI """ for i in range(len(tech_desc_1)): tech_desc_1[i] = tech_desc_1[i].replace('\\u0105', 'ą') tech_desc_1[i] = tech_desc_1[i].replace('\\u0119', 'ę') tech_desc_1[i] = tech_desc_1[i].replace('\\u0107', 'ć') tech_desc_1[i] = tech_desc_1[i].replace('\\u0144', 'ń') tech_desc_1[i] = tech_desc_1[i].replace('\\u015b', 'ś') tech_desc_1[i] = tech_desc_1[i].replace('\\u015a', 'Ś') tech_desc_1[i] = tech_desc_1[i].replace('\\u00f3', 'ó') tech_desc_1[i] = tech_desc_1[i].replace('\\u0141', 'Ł') tech_desc_1[i] = tech_desc_1[i].replace('\\u0142', 'ł') tech_desc_1[i] = tech_desc_1[i].replace('\\u017a', 'ź') tech_desc_1[i] = tech_desc_1[i].replace('\\u017b', 'Ż') tech_desc_1[i] = tech_desc_1[i].replace('\\u017c', 'ż') tech_desc_1[i] = tech_desc_1[i].replace('\\u017', 'Ź') tech_desc_1[i] = tech_desc_1[i].replace('\\u00ae', '®') tech_desc_1[i] = tech_desc_1[i].replace('\\u00b0', '°') tech_desc_1[i] = tech_desc_1[i].replace('\u00b0', '°') tech_desc_1[i] = tech_desc_1[i].replace('\u2070', '°') tech_desc_1[i] = tech_desc_1[i].replace('\\u2070', '°') tech_desc_1[i] = tech_desc_1[i].replace('\\u2013', '-') tech_desc_1[i] = tech_desc_1[i].replace('\u2013', '-') tech_desc_1[i] = tech_desc_1[i].replace('\\u2026', '...') tech_desc_1[i] = tech_desc_1[i].replace('\u2026', '...') tech_desc_1[i] = tech_desc_1[i].replace('\\n', '') tech_desc_1[i] = tech_desc_1[i].replace('\\/', '/') tech_desc_1[i] = tech_desc_1[i].replace(':', '') if len(tech_desc_1) < 12: n = len(tech_desc_1) else: n = 12 short = ['<ul>'] for i in range(0, n, 2): short.append(f'<li>{tech_desc_1[i]}: {tech_desc_1[i + 1]}</li>') short.append('</ul>') short = '\n'.join(short) print('------------ OPIS KRÓTKI ------------') print(short + '\n\n') return [reg, short, tech]
def go(): for data in data_list: driver.implicitly_wait(10) try: driver.find_element_by_xpath('//input[@name="sku"]').clear() driver.find_element_by_xpath('//input[@name="sku"]').send_keys(data[0]) except NoSuchElementException: wait('Enter') driver.find_element_by_xpath('//input[@name="sku"]').clear() driver.find_element_by_xpath('//input[@name="sku"]').send_keys(data[0]) driver.find_element_by_xpath('//button[@title="Szukaj"]').click() try: x = driver.find_element_by_xpath('//*[@id="messages"]/ul//span').text except NoSuchElementException: x = '' if x == 'Produkt został zapisany.': sleep(2) pyautogui.click(300, 605) else: pyautogui.click(300, 552) try: driver.find_element_by_xpath('//*[@id="content"]/div/div[2]/h3').get_attribute("innerText") except NoSuchElementException: undone.append(data[0]) continue driver.find_element_by_xpath('//a[@title="Porównywarki cenowe"]').click() driver.find_element_by_xpath('//select[@id="export_marketing"]/option[1]').click() driver.find_element_by_xpath('//button[@title="Zapisz"]').click() print(f'\n\nNiezrobione:') print('\n'.join(undone)) done.clear() undone.clear() data_list.clear()
def go(): i = 1 for data in data_list: driver.implicitly_wait(8) driver.find_element_by_xpath(f'//input[@name="{SEARCH_BY}"]').clear() driver.find_element_by_xpath( f'//input[@name="{SEARCH_BY}"]').send_keys(data[0]) driver.find_element_by_xpath('//button[@title="Szukaj"]').click() sleep(1) for j in range( 1, len( driver.find_elements_by_xpath( f'//table[@id="productGrid_table"]/tbody/tr')) + 1): if driver.find_elements_by_xpath( f'//table[@id="productGrid_table"]/tbody/tr' )[0].text == 'Nie znaleziono wpisów.': undone.append(data[0]) break try: if driver.find_element_by_xpath(f'//table[@id="productGrid_table"]/tbody/tr[{j}]/td[7]').text == data[0]\ and driver.find_element_by_xpath(f'//table[@id="productGrid_table"]/tbody/tr[{j}]/td[10]').text == 'Katalog, wyszukiwanie': driver.find_element_by_xpath( f'//table[@id="productGrid_table"]/tbody/tr[{j}]' ).click() break except StaleElementReferenceException: sleep(1) if driver.find_element_by_xpath(f'//table[@id="productGrid_table"]/tbody/tr[{j}]/td[7]').text == data[0] \ and driver.find_element_by_xpath(f'//table[@id="productGrid_table"]/tbody/tr[{j}]/td[10]').text == 'Katalog, wyszukiwanie': driver.find_element_by_xpath( f'//table[@id="productGrid_table"]/tbody/tr[{j}]' ).click() break try: driver.implicitly_wait(3) driver.find_element_by_xpath( '//*[@id="content"]/div/div[2]/h3').get_attribute("innerText") except NoSuchElementException: undone.append(data[0]) continue """ Początek instrukcji """ print(f"-- {i} -- {data[0]} --") i += 1 instrukcje(data[0]) """ Koniec instrukcji """ driver.find_element_by_xpath('//button[@title="Zapisz"]').click() try: driver.find_element_by_xpath('//button[@title="Dodaj produkt"]') except NoSuchElementException: driver.find_element_by_xpath('//button[@title="Powrót"]').click() undone.append(data[0]) print(f'\n\nNiezrobione:') print('\n'.join(undone)) done.clear() undone.clear() data_list.clear()
def instrukcje(data): # driver.find_element_by_xpath('//a[@title="Kategorie"]').click() # # TV = False # Audio = False # Audio_sub = False # # Category # for i in range(1, len(driver.find_elements_by_xpath('//div[@id="product-categories"]/ul[1]/div[1]/li[1]/ul[1]/li'))+1): # category = driver.find_element_by_xpath(f'//div[@id="product-categories"]/ul[1]/div[1]/li[1]/ul[1]/li[{i}]').text # category = category[:category.find('(')-1] # if 'TV i akcesoria RTV' == category: # TV = driver.find_element_by_xpath(f'//div[@id="product-categories"]/ul[1]/div[1]/li[1]/ul[1]/li[{i}]//input').is_selected() # # if 'Audio' == category: # Audio = driver.find_element_by_xpath(f'//div[@id="product-categories"]/ul[1]/div[1]/li[1]/ul[1]/li[{i}]//input').is_selected() # break # # # Audio subcategory # for i in range(1, len(driver.find_elements_by_xpath('//div[@id="product-categories"]/ul[1]/div[1]/li[1]/ul[1]/li[2]/ul[1]/*')) + 1): # category = driver.find_element_by_xpath(f'//div[@id="product-categories"]/ul[1]/div[1]/li[1]/ul[1]/li[2]/ul[1]/*[{i}]').text # category = category[:category.find('(') - 1] # if 'Kino domowe' == category or 'Głośniki' == category or 'Stereo' == category or 'Słuchawki' == category or 'Audio przenośne' == category: # Audio_sub = driver.find_element_by_xpath(f'//div[@id="product-categories"]/ul[1]/div[1]/li[1]/ul[1]/li[2]/ul[1]/*[{i}]//input').is_selected() # if Audio_sub: # break # # if not Audio and Audio_sub: # for i in range(1, len(driver.find_elements_by_xpath('//div[@id="product-categories"]/ul[1]/div[1]/li[1]/ul[1]/li')) + 1): # category = driver.find_element_by_xpath(f'//div[@id="product-categories"]/ul[1]/div[1]/li[1]/ul[1]/li[{i}]').text # category = category[:category.find('(') - 1] # if 'Audio' == category: # try: # driver.find_element_by_xpath(f'//div[@id="product-categories"]/ul[1]/div[1]/li[1]/ul[1]/li[{i}]//input').click() # except ElementClickInterceptedException: # sleep(3) # try: # driver.find_element_by_xpath(f'//div[@id="product-categories"]/ul[1]/div[1]/li[1]/ul[1]/li[{i}]//input').click() # except ElementClickInterceptedException: # print('Faliure: ElementClickInterceptedException') # undone.append(data) # break # if TV: # for i in range(1, len(driver.find_elements_by_xpath('//div[@id="product-categories"]/ul[1]/div[1]/li[1]/ul[1]/li')) + 1): # category = driver.find_element_by_xpath(f'//div[@id="product-categories"]/ul[1]/div[1]/li[1]/ul[1]/li[{i}]').text # category = category[:category.find('(') - 1] # if 'TV i akcesoria RTV' == category: # try: # driver.find_element_by_xpath(f'//div[@id="product-categories"]/ul[1]/div[1]/li[1]/ul[1]/li[{i}]//input').click() # except ElementClickInterceptedException: # sleep(3) # try: # driver.find_element_by_xpath(f'//div[@id="product-categories"]/ul[1]/div[1]/li[1]/ul[1]/li[{i}]//input').click() # except ElementClickInterceptedException: # print('Faliure: ElementClickInterceptedException') # undone.append(data) # break # driver.find_element_by_xpath('//select[@id="search_priority"]/option[text()="3"]').click() # link = 'https://matrixmedia.pl/' + driver.find_element_by_xpath('//input[@id="url_key"]').get_attribute('value') + '.html' # driver.switch_to.window(driver.window_handles[1]) # driver.get(link) # driver.switch_to.window(driver.window_handles[0]) # driver.find_element_by_xpath('//a[@title="Zestawy"]').click() # # for j in range(25): # pyautogui.click(1791, 388) # name = driver.find_element_by_xpath('//input[@name="product[name]"]').get_attribute('value').replace('Watch 3', # 'Watch3') # driver.find_element_by_xpath('//input[@name="product[name]"]').clear() # driver.find_element_by_xpath('//input[@name="product[name]"]').send_keys(name) # driver.find_element_by_xpath('//textarea[@name="product[additional_description]"]').clear() # driver.find_element_by_xpath('//textarea[@name="product[additional_description]"]').send_keys('<h2 style="text-align: center; font-size: 17px;"><strong>Kup Galaxy A71, <span style="color: #b41f21;"><br />a Galaxy A21s otrzymasz w prezencie.</span> </strong></h2>') # driver.find_element_by_xpath('//input[@name="product[additional_description_to]"]').clear() # driver.find_element_by_xpath('//input[@name="product[additional_description_to]"]').send_keys('12.02.2021 16:30') # driver.find_element_by_xpath('//input[@name="product[search_keywords]"]').send_keys('etui case do s21') # # promo = '<p style="text-align: center;"><strong>Kup, <a href="https://my-samsung.com/pl/mysamsung/offers/#/UTUVG9W2FCVXV/" style="color: #b41f21;" target="_blank">wypełnij formularz</a> i odbierz słuchawki <a href="https://matrixmedia.pl/sluchawki-samsung-galaxy-buds-sm-r170n-czarne.html/" style="color: #b41f21;" target="_blank">Galaxy Buds+</a><br />Szczegóły w <a href="https://stg-images.samsung.com/is/content/samsung/p5/pl/regulamin_GW3_bundle.pdf" style="color: #b41f21;" target="_blank">regulaminie</a>.</strong></p>\n' # short = driver.find_element_by_xpath( '//textarea[@name="product[short_description]"]').text if short.find('otrzymasz w prezencie!') != -1: short = short[short.find('</p>') + 4:] driver.find_element_by_xpath( '//textarea[@name="product[short_description]"]').clear() driver.find_element_by_xpath( '//textarea[@name="product[short_description]"]').send_keys(short)
def attributes(tech_desc, brand): tech_desc = tech_desc.lower() tech_desc = tech_desc.replace('<table id="plan_b" class="data-table"><tbody><tr class="specs_category"><td ' 'colspan="2">specyfikacja</td></tr><tr><td class="c_left">', '') tech_desc = tech_desc.replace('</td><td class="c_left">', ':') tech_desc = tech_desc.replace('</td></tr><tr><td class="c_left">', '\n') tech_desc = tech_desc.replace('</td></tr></tbody></table>', '') try: driver.find_element_by_xpath(f'//*[@id="marka"]/option[text()="{brand}"]').click() except NoSuchElementException: pass except ElementNotInteractableException: pass wysokosc = tech_desc[tech_desc.find('wysokość') + 9:] wysokosc = wysokosc[:wysokosc.find('\n')] wysokosc = wysokosc.replace(' ', '') wysokosc = wysokosc.replace('cm', '') wysokosc = wysokosc.replace(',', '.') try: wysokosc = float(wysokosc) if wysokosc < 84.9: driver.find_element_by_xpath(f'//*[@id="wysokosc"]/option[text()="do 84,9 cm"]').click() elif 84.9 < wysokosc < 99.9: driver.find_element_by_xpath(f'//*[@id="wysokosc"]/option[text()="od 85 do 99,9 cm"]').click() elif 100.0 < wysokosc < 129.9: driver.find_element_by_xpath(f'//*[@id="wysokosc"]/option[text()="od 100 do 129,9 cm"]').click() elif 130.0 < wysokosc < 159.9: driver.find_element_by_xpath(f'//*[@id="wysokosc"]/option[text()="od 130 do 159,9 cm"]').click() elif 160.0 < wysokosc < 179.9: driver.find_element_by_xpath(f'//*[@id="wysokosc"]/option[text()="od 170 do 179,9 cm"]').click() elif wysokosc > 180.0: driver.find_element_by_xpath(f'//*[@id="wysokosc"]/option[text()="od 180 cm"]').click() except NoSuchElementException: pass except ValueError: pass except ElementNotInteractableException: pass szerokosc = tech_desc[tech_desc.find('szerokość') + 10:] szerokosc = szerokosc[:szerokosc.find('\n')] szerokosc = szerokosc.replace(' ', '') szerokosc = szerokosc.replace('cm', '') szerokosc = szerokosc.replace(',', '.') try: szerokosc = float(szerokosc) if szerokosc < 39.9: driver.find_element_by_xpath(f'//*[@id="szerokosc"]/option[text()="do 39,9 cm"]').click() elif 40.0 < szerokosc < 50.9: driver.find_element_by_xpath(f'//*[@id="szerokosc"]/option[text()="od 40 do 50 cm"]').click() elif 51.0 < szerokosc < 60.9: driver.find_element_by_xpath(f'//*[@id="szerokosc"]/option[text()="od 51 do 60 cm"]').click() elif 61.0 < szerokosc < 79.9: driver.find_element_by_xpath(f'//*[@id="szerokosc"]/option[text()="od 60 do 79,9 cm"]').click() elif szerokosc > 80.0: driver.find_element_by_xpath(f'//*[@id="szerokosc"]/option[text()="od 80 cm"]').click() except ValueError: pass except NoSuchElementException: pass except ElementNotInteractableException: pass glebokosc = tech_desc[tech_desc.find('głębokość') + 10:] glebokosc = glebokosc[:glebokosc.find('\n')] glebokosc = glebokosc.replace(' ', '') glebokosc = glebokosc.replace('cm', '') glebokosc = glebokosc.replace(',', '.') try: glebokosc = float(glebokosc) if glebokosc < 35.9: driver.find_element_by_xpath('//*[@id="glebokosc"]/option[text()="od 31 do 35 cm"]').click() elif 36.0 < glebokosc < 39.9: driver.find_element_by_xpath('//*[@id="glebokosc"]/option[text()="od 36 do 40 cm"]').click() elif 40.0 < glebokosc < 44.9: driver.find_element_by_xpath('//*[@id="glebokosc"]/option[text()="40 do 44,9 cm"]').click() elif 45.0 < glebokosc < 49.9: driver.find_element_by_xpath('//*[@id="glebokosc"]/option[text()="od 45 do 49,9 cm"]').click() elif 50.0 < glebokosc < 54.9: driver.find_element_by_xpath('//*[@id="glebokosc"]/option[text()="od 50 do 54,9 cm"]').click() elif 55.0 < glebokosc < 59.9: driver.find_element_by_xpath('//*[@id="glebokosc"]/option[text()="od 55 do 59,9 cm"]').click() elif 60.0 < glebokosc < 64.9: driver.find_element_by_xpath('//*[@id="glebokosc"]/option[text()="od 60 do 65 cm"]').click() elif glebokosc < 65.0: driver.find_element_by_xpath('//*[@id="glebokosc"]/option[text()="od 65 cm"]').click() except ValueError: pass except NoSuchElementException: pass except ElementNotInteractableException: pass kolor = tech_desc[tech_desc.find('kolor') + 6:] kolor = kolor[:kolor.find('\n')] kolor = kolor.replace(' ', '') try: driver.find_element_by_xpath(f'//*[@id="dominujacy_odcien"]/option[text()="{kolor}"]').click() except NoSuchElementException: pass except ElementNotInteractableException: pass try: sterowanie = tech_desc[tech_desc.find('sterowanie') + 11:] sterowanie = sterowanie[:sterowanie.find('\n')] sterowanie = sterowanie.replace(' ', '') if 'mechan' in sterowanie: driver.find_element_by_xpath('//*[@id="sterowanie"]/option[text()="mechaniczne"]').click() else: driver.find_element_by_xpath(f'//*[@id="sterowanie"]/option[text()="{sterowanie}"]').click() except NoSuchElementException: pass except ElementNotInteractableException: pass halas = tech_desc[tech_desc.find('poziom hałasu') + 14:] halas = halas[:halas.find('\n')] halas = halas.replace(' ', '') halas = halas.replace('db', '') halas = halas.replace(',', '.') try: halas = float(halas) if halas < 36: driver.find_element_by_xpath('//*[@id="poziom_halasu"]/option[text()="do 36 dB"]').click() elif 36 <= halas <= 38: driver.find_element_by_xpath('//*[@id="poziom_halasu"]/option[text()="od 37 do 38 dB"]').click() elif 39 <= halas <= 40: driver.find_element_by_xpath('//*[@id="poziom_halasu"]/option[text()="od 39 do 40 dB"]').click() elif 41 <= halas <= 42: driver.find_element_by_xpath('//*[@id="poziom_halasu"]/option[text()="od 41 do 42 dB"]').click() elif 43 <= halas <= 44: driver.find_element_by_xpath('//*[@id="poziom_halasu"]/option[text()="od 43 do 44 dB"]').click() elif 44 < halas <= 45: driver.find_element_by_xpath('//*[@id="poziom_halasu"]/option[text()="od 44 do 45 dB"]').click() elif 46 <= halas <= 47: driver.find_element_by_xpath('//*[@id="poziom_halasu"]/option[text()="od 46 do 47 dB"]').click() elif 48 <= halas <= 49: driver.find_element_by_xpath('//*[@id="poziom_halasu"]/option[text()="od 48 do 49 dB"]').click() elif 51 <= halas <= 55: driver.find_element_by_xpath('//*[@id="poziom_halasu"]/option[text()="od 51 do 55 dB"]').click() elif 56 <= halas <= 60: driver.find_element_by_xpath('//*[@id="poziom_halasu"]/option[text()="od 56 do 60 dB"]').click() elif 61 <= halas <= 65: driver.find_element_by_xpath('//*[@id="poziom_halasu"]/option[text()="od 61 do 65 dB"]').click() elif 66 <= halas <= 70: driver.find_element_by_xpath('//*[@id="poziom_halasu"]/option[text()="od 66 do 70 dB"]').click() elif 71 <= halas <= 75: driver.find_element_by_xpath('//*[@id="poziom_halasu"]/option[text()="od 71 do 75 dB"]').click() elif 76 <= halas <= 80: driver.find_element_by_xpath('//*[@id="poziom_halasu"]/option[text()="od 76 do 80 dB"]').click() elif 81 <= halas <= 85: driver.find_element_by_xpath('//*[@id="poziom_halasu"]/option[text()="od 81 do 85 dB"]').click() elif 86 <= halas <= 90: driver.find_element_by_xpath('//*[@id="poziom_halasu"]/option[text()="od 86 do 90 dB"]').click() except ValueError: pass except NoSuchElementException: pass except ElementNotInteractableException: pass if tech_desc.find('wakacj') != -1: driver.find_element_by_xpath('//*[@id="funkcje_dodatkowe_lodowki"]/option[1]').click() if tech_desc.find('komora świeżości') != -1: driver.find_element_by_xpath('//*[@id="funkcje_dodatkowe_lodowki"]/option[text()="komora świeżości"]').click() if tech_desc.find('komora świeżości') != -1: driver.find_element_by_xpath('//*[@id="funkcje_dodatkowe_lodowki"]/option[text()="kostkarka"]').click() if tech_desc.find('kontrolą wilgotności') != -1: driver.find_element_by_xpath('//*[@id="funkcje_dodatkowe_lodowki"]/option[text()="szuflada z kontrolą ' 'wilgotności"]').click() poj_uz = tech_desc[tech_desc.find('pojemność użytkowa') + 27:] poj_uz = poj_uz[:poj_uz.find('\n')] poj_uz = poj_uz.replace(' ', '') poj_uz = poj_uz.replace('l', '') poj_uz = poj_uz.replace(',', '.') try: poj_uz = float(poj_uz) if poj_uz <= 30: driver.find_element_by_xpath('//*[@id="pojemnosc_uzytkowa"]/option[text()="do 30 litrów"]').click() elif 31 <= poj_uz <= 49: driver.find_element_by_xpath('//*[@id="pojemnosc_uzytkowa"]/option[text()="od 31 do 49 litrów"]').click() elif 50 <= poj_uz <= 59: driver.find_element_by_xpath('//*[@id="pojemnosc_uzytkowa"]/option[text()="od 50 do 59 litrów"]').click() elif 60 <= poj_uz <= 70: driver.find_element_by_xpath('//*[@id="pojemnosc_uzytkowa"]/option[text()="od 60 do 70 litrów"]').click() elif 71 <= poj_uz <= 90: driver.find_element_by_xpath('//*[@id="pojemnosc_uzytkowa"]/option[text()="od 71 do 90 litrów"]').click() elif 91 <= poj_uz <= 110: driver.find_element_by_xpath('//*[@id="pojemnosc_uzytkowa"]/option[text()="do 110 litrów"]').click() elif 110 <= poj_uz <= 130: driver.find_element_by_xpath('//*[@id="pojemnosc_uzytkowa"]/option[text()="od 110 do 130 litrów"]').click() elif 131 <= poj_uz <= 140: driver.find_element_by_xpath('//*[@id="pojemnosc_uzytkowa"]/option[text()="od 131 do 140 litrów"]').click() elif 141 <= poj_uz <= 159: driver.find_element_by_xpath('//*[@id="pojemnosc_uzytkowa"]/option[text()="od 141 do 159 litrów"]').click() elif 160 <= poj_uz <= 189: driver.find_element_by_xpath('//*[@id="pojemnosc_uzytkowa"]/option[text()="od 160 do 189 litrów"]').click() elif 190 <= poj_uz <= 209: driver.find_element_by_xpath('//*[@id="pojemnosc_uzytkowa"]/option[text()="od 190 do 209 litrów"]').click() elif 210 <= poj_uz <= 219: driver.find_element_by_xpath('//*[@id="pojemnosc_uzytkowa"]/option[text()="od 210 do 219 litrów"]').click() elif 220 <= poj_uz <= 249: driver.find_element_by_xpath('//*[@id="pojemnosc_uzytkowa"]/option[text()="od 220 do 249 litrów"]').click() elif 250 <= poj_uz <= 399: driver.find_element_by_xpath('//*[@id="pojemnosc_uzytkowa"]/option[text()="od 250 litrów"]').click() elif poj_uz > 400: driver.find_element_by_xpath('//*[@id="pojemnosc_uzytkowa"]/option[text()="od 400 litrów"]').click() except ValueError: pass except NoSuchElementException: pass except ElementNotInteractableException: pass
def electrolux(report_lab, product, model): driver.implicitly_wait(2) driver.get(product[6]) driver.find_element_by_xpath( '/html/body/div[2]/form/div[4]/div/div/div/div[1]/div/div[2]/table/tbody/tr[2]/td/input' ).send_keys('*****@*****.**') driver.find_element_by_xpath( '/html/body/div[2]/form/div[4]/div/div/div/div[1]/div/div[2]/table/tbody/tr[4]/td/input' ).send_keys('raza849') driver.find_element_by_xpath( '/html/body/div[2]/form/div[4]/div/div/div/div[1]/div/div[2]/table/tbody/tr[7]/td/input' ).click() """ Obrazki produktu """ imgs_desc = driver.find_elements_by_xpath( '//*[@id="Family"]//div[@class="colPicture"]//img') prod_img_names = [] for link in imgs_desc: prod_img_name = link.get_attribute('src') prod_img_name = prod_img_name[prod_img_name.rfind('/') + 1:] prod_img_name = prod_img_name[:prod_img_name.find('.')] prod_img_names.append(prod_img_name) """ Opis graficzny """ tiles = driver.find_elements_by_xpath( '//div[@id="KeyFeatures"]/div[@class="SecondaryBenefits"]/div[@class="sb"]' ) full = [] for i in range(len(tiles)): content = tiles[i].text.split('\n') header = f'<div class="two-col-asymmetrically"><div class="right-side"><h2 class="important-header">{content[0]}</h2>' description = f'<p style="font-size: large; text-align: center;">{content[1]}</p></div>' link = driver.find_element_by_xpath( f'//div[@id="KeyFeatures"]/div[@class="SecondaryBenefits"]/div[@class="sb"][{i + 1}]//img' ).get_attribute('src') if 'gif' in link: link = 'random ' full.append([header, description, link]) for i in range(len(full)): # obetnij link i rozszerzenie (do znalezienia nazwy obrazka do pobrania) full[i][2] = full[i][2][full[i][2].rfind('/') + 1:] full[i][2] = full[i][2][:full[i][2].find('.')] driver.find_element_by_xpath('//a[contains(text(), "Medias")]').click() driver.switch_to.window(driver.window_handles[2]) # zbierz wszystkie nazwy plików rows = driver.find_elements_by_xpath('//li') rows_links = driver.find_elements_by_xpath('//li/a') rows_text = [row.text for row in rows] # podczas wybierania losowego obrazka łatwiej znaleźć ładny od końca rows_text = rows_text[::-1] # oddziel obrazki znalezione, aby ich nie powielać used = [x[2] for x in full if x[2] != 'random'] for prod_img_name in prod_img_names: used.append(prod_img_name) for i in range(len(full)): img_link = False for row_t in rows_text: link_to_image = rows_links[rows_text.index(row_t) * (-1) - 1].get_attribute('href') name_of_image = row_t[row_t.find(':') + 2:row_t.find('.')] # Odrzuć inne możliwości niż "700x700 Presentation" if '700x700 Presentation' not in row_t: continue # odrzucaj rozszerzenia "bmp" oraz "eps" excension = link_to_image[-5:].lower() if 'bmp' in excension or 'eps' in excension: continue # sprawdź czy znaleziony wiersz należy do tych z opisu graficznego # Jeżeli nie został ustlaony, to wybierz pierwsz-lepszy if full[i][2] == 'random': if name_of_image not in used: img_link = link_to_image print( f'Wybrano: {row_t} w miejce Random ({name_of_image})') break elif full[i][2] in row_t: img_link = link_to_image print( f'Wybrano: {row_t} w miejce {full[i][2]} ({name_of_image})' ) break # na wszelki wypadek jeżeli nie znajdzie poszukiwanego zdjęcia, to wybierze losowe if not img_link and name_of_image not in used: print( f'Wybrano: {row_t} w miejce obrazka produktu ({name_of_image})' ) img_link = link_to_image # jak już tu jesteś, to pobierz też obrazki produktu for prod_img_name in prod_img_names: if prod_img_name in row_t: prod_img_link = link_to_image ImgRefractor.prod_img(f'{file_path}/{model}', prod_img_link, i) break if not img_link: print(f'Nie znaleziono obrazka dla: {full[i][2]}') continue print(img_link) # dodaj nazwę pliku do listy użytych ("used") if name_of_image not in used: used.append(name_of_image) size, file_type = ImgRefractor.desc_img(f'{file_path}/{model}', img_link, i) full[i][ 2] = f'<img src="https://matrixmedia.pl/media/wysiwyg/Electrolux/{model}/{i}.{file_type}" /></div>' print(used) driver.switch_to.window(driver.window_handles[1]) """ Opis krótki """ try: # weź do 8 elementów z opisu funkcji. Pierwszy element to słowo "funkcje" short = driver.find_element_by_id('FeaturesBullet').text.split( '\n')[1:9] for i in range(len(short)): while True: if short[i][0] == ' ': short[i] = short[i][1:] else: # dodaj tagi HTML'a short[i] = f'<li>{short[i]}<li>' break short = '<ul>' + ''.join(short) + '</ul>' except NoSuchElementException: short = 'Popraw' print('Coś jest nie tak ze ścieżką w Selenium do krótkiego opisu') """ Opis techniczny """ tech = [ '<table id="plan_b" class="data-table"><tbody><tr class="specs_category"><td colspan="2">Specyfikacja</td></tr>' ] for row in driver.find_elements_by_xpath( '//div[@id="TechnicalSpecs"]//div[@class="element"]'): name, value = row.text.split('\n') tech.append( f'<tr><td class="c_left">{name}</td><td class="c_left">{value}</td></tr>' ) tech.append('</tbody></table>') full = [['<div class="product-description-section">'] ] + full + [['</div>']] reg = [] for ele in full: reg.append(''.join(ele)) reg = ''.join(reg) tech = ''.join(tech) return [reg, short, tech]