use mobile API to parse housing informations
This commit is contained in:
parent
20682b3e94
commit
2a860200b9
2 changed files with 41 additions and 49 deletions
|
|
@ -20,10 +20,9 @@
|
||||||
|
|
||||||
import json
|
import json
|
||||||
|
|
||||||
from weboob.capabilities.base import NotAvailable
|
|
||||||
from weboob.tools.browser import BaseBrowser
|
from weboob.tools.browser import BaseBrowser
|
||||||
|
|
||||||
from .pages import SearchResultsPage, HousingPage, HousingPhotosPage
|
from .pages import SearchResultsPage, HousingPage
|
||||||
|
|
||||||
|
|
||||||
__all__ = ['SeLogerBrowser']
|
__all__ = ['SeLogerBrowser']
|
||||||
|
|
@ -36,8 +35,7 @@ class SeLogerBrowser(BaseBrowser):
|
||||||
PAGES = {
|
PAGES = {
|
||||||
'http://www.seloger.com/(pre)?recherche.htm.*': SearchResultsPage,
|
'http://www.seloger.com/(pre)?recherche.htm.*': SearchResultsPage,
|
||||||
'http://www.seloger.com/annonces.htm.*': SearchResultsPage,
|
'http://www.seloger.com/annonces.htm.*': SearchResultsPage,
|
||||||
'http://www.seloger.com/annonces/.*': HousingPage,
|
'http://ws.seloger.com/annonceDetail.xml\?idAnnonce=(\d+)': HousingPage,
|
||||||
'http://www.seloger.com/\d+/incl_detail_annonce_load_diapo_new.htm': HousingPhotosPage,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
def search_geo(self, pattern):
|
def search_geo(self, pattern):
|
||||||
|
|
@ -61,12 +59,9 @@ class SeLogerBrowser(BaseBrowser):
|
||||||
return self.page.iter_housings()
|
return self.page.iter_housings()
|
||||||
|
|
||||||
def get_housing(self, id, obj=None):
|
def get_housing(self, id, obj=None):
|
||||||
self.location('/%d/detail_new.htm' % int(id))
|
self.location(self.buildurl('http://ws.seloger.com/annonceDetail.xml', idAnnonce=id))
|
||||||
|
|
||||||
assert self.is_on_page(HousingPage)
|
assert self.is_on_page(HousingPage)
|
||||||
housing = self.page.get_housing(obj)
|
housing = self.page.get_housing(obj)
|
||||||
|
|
||||||
self.location('/%d/incl_detail_annonce_load_diapo_new.htm' % int(id))
|
|
||||||
housing.photos = list(self.page.iter_photos()) or NotAvailable
|
|
||||||
|
|
||||||
return housing
|
return housing
|
||||||
|
|
|
||||||
|
|
@ -18,21 +18,21 @@
|
||||||
# along with weboob. If not, see <http://www.gnu.org/licenses/>.
|
# along with weboob. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
|
||||||
import re
|
|
||||||
from datetime import date
|
from datetime import date
|
||||||
|
from dateutil.parser import parse as parse_date
|
||||||
|
|
||||||
from weboob.tools.browser import BasePage, BrokenPageError
|
from weboob.tools.browser import BasePage
|
||||||
from weboob.capabilities.base import NotAvailable
|
from weboob.capabilities.base import NotAvailable
|
||||||
from weboob.capabilities.housing import Housing, HousingPhoto
|
from weboob.capabilities.housing import Housing, HousingPhoto
|
||||||
|
|
||||||
|
|
||||||
__all__ = ['SearchResultsPage', 'HousingPage', 'HousingPhotosPage']
|
__all__ = ['SearchResultsPage', 'HousingPage']
|
||||||
|
|
||||||
|
|
||||||
def sanitarize_cost(t):
|
|
||||||
return int(float(t.strip(u' \t\u20ac\xa0c€\n\r').replace(u'\xa0', u'').replace(',', '.')))
|
|
||||||
|
|
||||||
class SearchResultsPage(BasePage):
|
class SearchResultsPage(BasePage):
|
||||||
|
def sanitarize_cost(t):
|
||||||
|
return int(float(t.strip(u' \t\u20ac\xa0c€\n\r').replace(u'\xa0', u'').replace(',', '.')))
|
||||||
|
|
||||||
def iter_housings(self):
|
def iter_housings(self):
|
||||||
for div in self.document.getroot().cssselect('div.ann_ann_border'):
|
for div in self.document.getroot().cssselect('div.ann_ann_border'):
|
||||||
id = div.find('a').attrib['id'][3:]
|
id = div.find('a').attrib['id'][3:]
|
||||||
|
|
@ -42,11 +42,11 @@ class SearchResultsPage(BasePage):
|
||||||
housing.title = head.xpath('.//span[@class="mea1"]/a')[0].text.strip()
|
housing.title = head.xpath('.//span[@class="mea1"]/a')[0].text.strip()
|
||||||
|
|
||||||
parts = head.xpath('.//span[@class="mea2"]')[0].text.strip().split('+')
|
parts = head.xpath('.//span[@class="mea2"]')[0].text.strip().split('+')
|
||||||
housing.cost = sanitarize_cost(parts[0])
|
housing.cost = self.sanitarize_cost(parts[0])
|
||||||
if len(parts) > 1:
|
if len(parts) > 1:
|
||||||
for span in head.xpath('.//span[@class="addprixfr"]/span/strong'):
|
for span in head.xpath('.//span[@class="addprixfr"]/span/strong'):
|
||||||
if span.text.strip() == u'Charges\xa0:':
|
if span.text.strip() == u'Charges\xa0:':
|
||||||
housing.cost += sanitarize_cost(span.tail)
|
housing.cost += self.sanitarize_cost(span.tail)
|
||||||
housing.currency = u'€'
|
housing.currency = u'€'
|
||||||
|
|
||||||
sub = div.xpath('.//div[@class="rech_desc_right_photo"]')[0]
|
sub = div.xpath('.//div[@class="rech_desc_right_photo"]')[0]
|
||||||
|
|
@ -63,45 +63,42 @@ class SearchResultsPage(BasePage):
|
||||||
|
|
||||||
class HousingPage(BasePage):
|
class HousingPage(BasePage):
|
||||||
def get_housing(self, housing=None):
|
def get_housing(self, housing=None):
|
||||||
doc = self.document.getroot()
|
|
||||||
if housing is None:
|
if housing is None:
|
||||||
housing = Housing(self.url.split('/')[-1].rstrip('.htm'))
|
housing = Housing(self.groups[0])
|
||||||
|
|
||||||
housing.title = doc.xpath('//head/title')[0].text
|
details = self.document.getroot().xpath('//detailannonce')[0]
|
||||||
housing.text = doc.xpath('//head/meta[@name="description"]')[0].attrib['content']
|
if details.find('titre') is None:
|
||||||
txt = doc.xpath('//meta[@itemprop="price"]')[0].attrib['content'].strip()
|
return None
|
||||||
m = re.match(u'(\d+)\xa0\u20ac(\+ch|cc)(Charges: (\d+)\u20ac)?', txt)
|
|
||||||
if not m:
|
|
||||||
raise BrokenPageError('Unable to parse price %r' % txt)
|
|
||||||
|
|
||||||
housing.cost = sanitarize_cost(m.group(1))
|
housing.title = details.find('titre').text
|
||||||
if m.group(4):
|
housing.text = details.find('descriptif').text.strip()
|
||||||
housing.cost += sanitarize_cost(m.group(4))
|
housing.cost = int(details.find('prix').text)
|
||||||
housing.currency = u'€'
|
housing.currency = u'€'
|
||||||
|
housing.date = parse_date(details.find('dtfraicheur').text)
|
||||||
housing.date = date(*map(int, reversed(doc.xpath('//span[@class="maj"]/b')[0].text.split(' / '))))
|
housing.area = float(details.find('surface').text)
|
||||||
housing.area = int(doc.xpath('//li[@title="Surface"]/b')[0].text.strip(u'\xa0m\xb2'))
|
housing.phone = details.find('contact').find('telephone').text
|
||||||
|
|
||||||
try:
|
try:
|
||||||
housing.station = doc.xpath('//dd[@class="metro_paris"]')[0].text.strip()
|
housing.station = details.find('proximite').text
|
||||||
except IndexError:
|
except AttributeError:
|
||||||
housing.station = NotAvailable
|
housing.station = NotAvailable
|
||||||
|
|
||||||
try:
|
housing.location = details.find('adresse').text
|
||||||
housing.phone = doc.xpath('//div[@class="tel"]')[0].text.strip()
|
if not housing.location and details.find('quartier') is not None:
|
||||||
except IndexError:
|
housing.location = details.find('quartier').text
|
||||||
housing.phone = NotAvailable
|
if not housing.location:
|
||||||
|
|
||||||
try:
|
|
||||||
housing.location = doc.xpath('//div[@class="adresse"]/b')[0].tail.strip().replace('\r\n', ' ')
|
|
||||||
except IndexError:
|
|
||||||
housing.location = NotAvailable
|
housing.location = NotAvailable
|
||||||
|
|
||||||
return housing
|
housing.photos = []
|
||||||
|
for photo in details.xpath('./photos/photo'):
|
||||||
|
if photo.find('bigurl').text:
|
||||||
|
url = photo.find('bigurl').text
|
||||||
|
else:
|
||||||
|
url = photo.find('stdurl').text
|
||||||
|
housing.photos.append(HousingPhoto(url))
|
||||||
|
|
||||||
class HousingPhotosPage(BasePage):
|
housing.details = {}
|
||||||
def iter_photos(self):
|
for detail in details.xpath('./details/detail'):
|
||||||
for i, li in enumerate(self.document.getroot().xpath('//li')):
|
housing.details[detail.find('libelle').text.strip()] = detail.find('valeur').text or 'N/A'
|
||||||
photo = HousingPhoto(i)
|
|
||||||
photo.url = li.attrib['rel'].split('|')[0]
|
return housing
|
||||||
yield photo
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue