36 lines
1.1 KiB
Python
36 lines
1.1 KiB
Python
import requests
|
|
from lxml import html
|
|
from ins_record import add_record_to_airtable
|
|
|
|
# Adres URL strony do pobrania
|
|
url = 'https://papermodeling.net/index.php?route=common/home'
|
|
|
|
# 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="content"]/div[1]/div[2]/div[2]')
|
|
|
|
# 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 i linków zawierających 'productcarousel'
|
|
unique_links = set(all_links) # Usunięcie duplikatów
|
|
filtered_links = [link for link in unique_links if 'productcarousel' not in link]
|
|
|
|
# Wyświetlenie przefiltrowanych linków
|
|
for link in filtered_links:
|
|
print(link)
|
|
add_record_to_airtable("Oriel", link)
|