import requests from lxml import html # Adres URL strony do pobrania url = 'https://sklep.gpm.pl/sklep-nowosci' # Pobranie zawartości strony response = requests.get(url) response.raise_for_status() # Sprawdza, czy żądanie zakończyło się sukcesem # Parsowanie zawartości HTML tree = html.fromstring(response.content) # Wybór elementów za pomocą XPath elements = tree.xpath('//*[@id="center"]/div/div') # Lista do przechowywania linków all_links = [] # Sprawdzenie, czy znaleziono jakiekolwiek elementy if elements: for element in elements: # Wyodrębnienie linków z wnętrza wybranego elementu links = element.xpath('.//a/@href') all_links.extend(links) # Usunięcie duplikatów, linków zawierających 'javascript:', 'zestawy wak', 'wyprzedaż', 'laser' unique_links = set(all_links) # Usunięcie duplikatów filtered_links = [ link for link in unique_links if 'javascript:' not in link and 'zestawy wak' not in link and 'wyprzedaz' not in link and 'laser' not in link and 'antykwariat' not in link and 'literatura' not in link and 'aakcesoria' not in link ] # Dodatkowe filtrowanie linków zawierających 'wyprzedaż' i 'wak' final_filtered_links = [ link for link in filtered_links if 'wyprzedaż' not in link and 'wak' not in link ] # Wyświetlenie przefiltrowanych linków for link in final_filtered_links: print(link)