-
Notifications
You must be signed in to change notification settings - Fork 0
/
nebo.py
63 lines (49 loc) · 1.57 KB
/
nebo.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import requests
from bs4 import BeautifulSoup
from django.core.files.base import ContentFile
from bso_nsk.catalog.models import Product
r = requests.session()
content = r.get("https://nebo18.ru/")
soup = BeautifulSoup(content.content, "html.parser")
for sect in [
"elementor-element-7532b48",
"elementor-element-0cadaa7",
"elementor-element-a5b5273",
"elementor-element-79be620",
"elementor-element-05a0ff7",
]:
section = soup.find("section", class_=sect)
container = section.find("div", class_="elementor-container")
sort = 31
for item in container.find_all("div", class_="elementor-column"):
data = item.find("div", class_="elementor-widget-container")
image = None
name = None
zalupa = False
desc = ""
for h3 in data.find_all("h3"):
if h3.find("a"):
image = h3.find("a").get("href")
else:
name = h3.get_text()
if image is None:
image = data.find("p").find("a").get("href")
zalupa = True
for text in data.find_all("p"):
if zalupa:
zalupa = False
continue
desc += f"{text.get_text()}<br>\n"
image_r = r.get(image)
image_content = image.content
filename = image.split('/')[-1]
p = Product.objects.create(
category_id=3,
name=name,
code=name,
description=desc,
sort=sort
)
p.image.save(filename, ContentFile(data))
sort += 1
print("next")