-
Notifications
You must be signed in to change notification settings - Fork 0
/
site_temp.py
45 lines (35 loc) · 1.49 KB
/
site_temp.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
from flatr.site import Site
from bs4.element import Tag, ResultSet
class ClassName(Site):
PREPEND = 'prepend for website'
HEADERS = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.84 Safari/537.36',
'accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8',
}
def __init__(self, link: str):
super().__init__(link, headers=ClassName.HEADERS)
def _get_raw_listings(self) -> ResultSet:
return self.soup.find_all('css tag', {'class': 'listing class'})
def _get_title(self, listing: Tag) -> str:
try:
raw_title = listing.select('CSS selector')[0].a.string
location = listing.select('CSS selector')[0].a.string
return f'{raw_title} at {location}'
except Exception:
return self.MISSING
def _get_price(self, listing: Tag) -> str:
try:
return str(listing.select('CSS selector')[0].string)
except Exception:
return self.MISSING
def _get_availability(self, listing: Tag) -> str:
try:
return str(listing.select('CSS selector')[0].string)
except Exception:
return self.MISSING
def _get_link(self, listing: Tag) -> str:
try:
raw_link = str(listing.select('CSS selector')[0].a['href'])
return ClassName.PREPEND + raw_link
except Exception:
return self.MISSING