-
Notifications
You must be signed in to change notification settings - Fork 1
/
pazar3.py
66 lines (53 loc) · 1.54 KB
/
pazar3.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
62
63
64
65
66
import requests
from bs4 import BeautifulSoup
import re
def htmldelete(string, index):
string = string.split('>')[1]
string = string.split('<')[0]
newstr = ""
for i in range(len(string) - index):
newstr += string[i + index]
return newstr
def eurtomkd(string):
string = string.replace(".", "")
if "МКД" not in string:
string = string.replace(" ЕУР", "")
string = string.replace(" ", "")
try:
string = str(int(string) * 60) + " МКД"
except:
string = "No Price"
return string
else:
return string
def gethref(string):
try:
return re.findall(r'"(.*?)"', string)[1]
except:
return ""
def getcity(string):
try:
return string.split("/")[4]
except:
return ""
URL = "https://www.pazar3.mk/oglasi/elektronika/delovi-za-kompjuteri-dodatoci/se-prodava"
page = requests.get(URL)
soup = BeautifulSoup(page.content, "html.parser")
items = soup.find_all(class_="Link_vis")
prices = soup.find_all(class_="list-price")
links = soup.find_all("a", class_="Link_vis", href=True)
for i in range(len(prices)):
string = str(items[i])
string = htmldelete(string, 0)
print(string)
string = str(prices[i])
string = htmldelete(string, 1)
string = eurtomkd(string)
string = string.replace('\n', '')
print(string)
string = str(links[i])
string = gethref(string)
print("pazar3.mk" + string)
string = getcity(string)
string = string.capitalize()
print(string + '\n')