-
Notifications
You must be signed in to change notification settings - Fork 0
/
super6.py
61 lines (57 loc) · 2.78 KB
/
super6.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
58
59
60
61
import requests
from bs4 import BeautifulSoup
import time
HOME_URL = "https://www.superseis.com.py/default.aspx"
NoneType = type(None)
def parsing(HOME_URL):
try:
response = requests.get(HOME_URL)
if response.status_code == 200:
html = response.content
soup_main = BeautifulSoup(html,"html.parser")
ul_to_section = soup_main.find("ul",class_="wsmenu-submenu-sub wstitemright clearfix")
link_to_section = ul_to_section.find_all("a",class_ = "collapsed")
i = 0
print(len(link_to_section))
for link in link_to_section:
link = link.get("href")
if type(link) != NoneType:
print(f"{link} ESTE ES EL LINK DE LA SECCION" )
i = i + 1
print(i)
if "https://www.superseis.com.py" in link:
hyperlink = link
r = requests.get(hyperlink)
html_ = r.content
soup = BeautifulSoup(html_,"html.parser")
find_img = soup.find("div",class_="picture")
condition = not type(find_img) == NoneType
if condition:
product_img = find_img.find("img")
product_img = product_img.get("src")
img = requests.get(product_img)
find_name = soup.find("h2",class_="product-title")
name = find_name.find("a")
name_file = name.text.replace("/","")
find_price = soup.find("span",class_="price-label")
price = find_price.text
with open(f"./super6/product_name/{i}{name_file}.txt",'w') as f:
f.write(name_file)
f.write("\n\n")
f.write(price)
with open(f"./super6/productos/{name_file}{i}.jpg",'wb') as picture:
picture.write(img.content)
else:
print("It's a none")
continue
else:
print("Not a link.")
continue
else:
print(link)
continue
else:
raise ValueError(f'Error: {response.status_code}')
except ValueError as ve:
print(ve)
parsing(HOME_URL)