Files
DBAdmin/inbox/Python/getAILinks/get_Shipyard.py
T
2026-05-18 06:40:19 +00:00

39 lines
1.0 KiB
Python

import requests
from lxml import html
# Adres URL strony do pobrania
url = 'https://model-shipyard.com/pl/20-zaglowce'
# 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="product_list"]')
# 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
unique_links = set(all_links)
# Filtracja linków
filtered_links = [
link for link in unique_links
if 'laserowo' not in link and 'author' not in link and 'category' not in link and 'page' not in link
]
# Wyświetlenie przefiltrowanych linków
for link in filtered_links:
print(link)