wicej zmian
This commit is contained in:
60
mayo.py
60
mayo.py
@@ -54,7 +54,7 @@ class MayoSession:
|
||||
- wykończenie
|
||||
"""
|
||||
r = self.session.get(url)
|
||||
r.encoding = "utf-8"
|
||||
r.encoding = 'ISO-8859-2' # Poprawione kodowanie na podstawie tagu meta w HTML
|
||||
soup = BeautifulSoup(r.text, "html.parser")
|
||||
|
||||
# --- nr zamówienia ---
|
||||
@@ -67,45 +67,33 @@ class MayoSession:
|
||||
|
||||
# --- kolory i wykończenie ---
|
||||
color_sections = {}
|
||||
# Znajdź wszystkie <p> zawierające <a> z tekstem "KOLOR"
|
||||
for p in soup.find_all("p"):
|
||||
a_tag = p.find("a")
|
||||
if not a_tag:
|
||||
continue
|
||||
|
||||
# Szukamy linków (a) wewnątrz pogrubienia (b), które zawierają "KOLOR -"
|
||||
for a_tag in soup.select('b > a'):
|
||||
title = a_tag.get_text(strip=True)
|
||||
if title.startswith("KOLOR"):
|
||||
# np. "KOLOR - Top"
|
||||
if title.startswith("KOLOR -"):
|
||||
label = title.replace("KOLOR - ", "").strip()
|
||||
|
||||
# znajdź <td> z wartością koloru (niedaleko tego <p>)
|
||||
td = p.find_parent("td")
|
||||
if td:
|
||||
# przejdź do następnego <td>, tam jest <span> z kolorem
|
||||
next_td = td.find_next_sibling("td")
|
||||
if next_td:
|
||||
span = next_td.find("span")
|
||||
if span:
|
||||
text = span.get_text(" ", strip=True)
|
||||
# usuń ewentualne znaki nadmiarowe
|
||||
text = re.sub(r"\s+", " ", text)
|
||||
color_match = re.search(r"^\s*-\s*([A-Z0-9-]+)", text)
|
||||
if color_match:
|
||||
text = color_match.group(1)
|
||||
color_sections[label] = text
|
||||
|
||||
# --- normalizacja nazewnictwa ---
|
||||
color_top = color_sections.get("Top")
|
||||
color_body = color_sections.get("Korpus")
|
||||
color_neck = color_sections.get("Szyjka")
|
||||
color_head = color_sections.get("Główka")
|
||||
finish = color_sections.get("Wykończenie [K/C]")
|
||||
|
||||
parent_td = a_tag.find_parent('td')
|
||||
if parent_td:
|
||||
value_td = parent_td.find_next_sibling('td')
|
||||
if value_td:
|
||||
text = value_td.get_text(" ", strip=True)
|
||||
value = None
|
||||
# Wartość jest zazwyczaj pomiędzy myślnikiem a ukośnikiem
|
||||
match = re.search(r'-\s*([^/]+)', text)
|
||||
# print(f"label: {label}, match: {match}, text: {text}")
|
||||
if match:
|
||||
value = match.group(1).strip()
|
||||
color_sections[label] = value
|
||||
|
||||
return {
|
||||
"order_number": order_number,
|
||||
"model": model,
|
||||
"color_top": color_top,
|
||||
"color_body": color_body,
|
||||
"color_neck": color_neck,
|
||||
"color_head": color_head,
|
||||
"finish": finish,
|
||||
"color_top": color_sections.get("Top"),
|
||||
"color_body": color_sections.get("Korpus"),
|
||||
"color_neck": color_sections.get("Szyjka"),
|
||||
"color_head": color_sections.get("Główka"),
|
||||
"finish_kc": color_sections.get("Wykończenie [K/C]"),
|
||||
"finish_s": color_sections.get("Wykończenie [S]"),
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user