39 lines
1.0 KiB
Python
39 lines
1.0 KiB
Python
import requests
|
|
from lxml import html
|
|
|
|
# Adres URL strony do pobrania
|
|
url = 'https://www.wak.pl/wak-m-1.html'
|
|
|
|
# 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="SrodekKolumna"]/section/div[1]')
|
|
|
|
# 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 'lufy' not in link and 'zapytanie' not in link and 'wak-m-1' not in link
|
|
]
|
|
|
|
# Wyświetlenie przefiltrowanych linków
|
|
for link in filtered_links:
|
|
print(link)
|