def search(self, plz): page = 1 per_page = 50 count, count_beg = 1000, 1000 while True: offset = str(per_page * (page - 1)) if page == 1: response = yield from self.post(data={ 'jahr': 'jahr', 'name': '', 'plz': plz, 'ort': '', 'suchtypBetrag': 'betrag_massnahme', 'operator': 'eq', 'betrag': '', 'suchtypEgfl': 'egfl_alle' }) dom = response.dom() form_data = get_form_data(dom.xpath('.//form[@id="data"]')[0]) if 'count' not in form_data: # No results return None count = form_data['count'] count_beg = form_data['countBeg'] response = yield from self.post(data={ 'jahr': 'jahr', 'name': '', 'ort': '', 'plz': plz, 'suchtypBetrag': 'betrag_massnahme', 'operator': 'eq', 'betrag': '', 'suchtypEgfl': 'egfl_alle', 'suchtypEler': 'eler_alle', 'viewOffset': str(offset), 'viewOrderdir': 'asc', 'viewOrderby': 'zahlungsempfaenger', 'viewCount': str(count), 'viewCountBeg': str(count_beg), 'viewLimit': str(per_page), 'offset': str(offset), 'dir': 'asc', 'order': 'zahlungsempfaenger', 'count': str(count), 'countBeg': str(count_beg), 'prevLimit': str(per_page), 'limit': str(per_page), 'seite': str(page) }) dom = response.dom() buttons = dom.xpath('.//button[@name="showBeg"]') button_values = [x.attrib['value'] for x in buttons] yield from self.schedule_many(self.detail, button_values) nav_text = dom.xpath('.//div[@id="listNavRight"]')[0].text_content() print('%s lines for %s - now on page %d' % (count, plz, page)) if 'von %d' % page in nav_text: break page += 1 print('Going to page %d of %s' % (page, plz))
def perform_search(self, session, year, location): yield from session.get(self.TERMS_URL) response = yield from session.get(self.START_URLS[year]) form = response.xpath('.//form[@name="seachForm"]')[0] data = get_form_data(form) data['location'] = location response = yield from session.post(self.SEARCH_URL, data=data) return response
async def initialize_session(self, session, year): response = await session.get() form = response.dom().xpath('//form[@id="search-form"]')[0] form_data = get_form_data(form) form_data.update({ 'lower': '-1', 'upper': '-1', 'year': year, 'company': '', 'prefecture': '', 'municipality': '', 'regime': '', 'submit': '1' }) response = await session.post(data=form_data) form_data['total_rows'] = response.xpath( './/input[@name="total_rows"]/@value')[0] return form_data
def search(self, plz): page = 1 per_page = 50 count, count_beg = 1000, 1000 while True: offset = str(per_page * (page - 1)) if page == 1: response = yield from self.post( data={ 'jahr': 'jahr', 'name': '', 'plz': plz, 'ort': '', 'suchtypBetrag': 'betrag_massnahme', 'operator': 'eq', 'betrag': '', 'suchtypEgfl': 'egfl_alle' }) dom = response.dom() form_data = get_form_data(dom.xpath('.//form[@id="data"]')[0]) if 'count' not in form_data: # No results return None count = form_data['count'] count_beg = form_data['countBeg'] response = yield from self.post( data={ 'jahr': 'jahr', 'name': '', 'ort': '', 'plz': plz, 'suchtypBetrag': 'betrag_massnahme', 'operator': 'eq', 'betrag': '', 'suchtypEgfl': 'egfl_alle', 'suchtypEler': 'eler_alle', 'viewOffset': str(offset), 'viewOrderdir': 'asc', 'viewOrderby': 'zahlungsempfaenger', 'viewCount': str(count), 'viewCountBeg': str(count_beg), 'viewLimit': str(per_page), 'offset': str(offset), 'dir': 'asc', 'order': 'zahlungsempfaenger', 'count': str(count), 'countBeg': str(count_beg), 'prevLimit': str(per_page), 'limit': str(per_page), 'seite': str(page) }) dom = response.dom() buttons = dom.xpath('.//button[@name="showBeg"]') button_values = [x.attrib['value'] for x in buttons] yield from self.schedule_many(self.detail, button_values) nav_text = dom.xpath( './/div[@id="listNavRight"]')[0].text_content() print('%s lines for %s - now on page %d' % (count, plz, page)) if 'von %d' % page in nav_text: break page += 1 print('Going to page %d of %s' % (page, plz))
async def search(self, plz): page = 1 per_page = 50 count, count_beg = 1000, 1000 while True: offset = str(per_page * (page - 1)) if page == 1: response = await self.post(data={ 'jahr': self.YEAR, 'name': '', 'plz': plz, 'ort': '', 'suchtypBetrag': 'betrag_massnahme', 'operator': 'eq', 'betrag': '', 'suchtypEgfl': 'egfl_alle' }) text = response.text() if 'Es liegen mehr als 1500 Ergebnisse vor' in text: raise ValueError('Search %s result in too many!' % plz) dom = response.dom() form_data = get_form_data(dom.xpath('.//form[@id="data"]')[0]) if 'count' not in form_data: # No results return None count = form_data['count'] count_beg = form_data['countBeg'] response = await self.post(data={ 'jahr': self.YEAR, 'name': '', 'ort': '', 'plz': plz, 'suchtypBetrag': 'betrag_massnahme', 'operator': 'eq', 'betrag': '', 'suchtypEgfl': 'egfl_alle', 'suchtypEler': 'eler_alle', 'viewOffset': str(offset), 'viewOrderdir': 'asc', 'viewOrderby': 'zahlungsempfaenger', 'viewCount': str(count), 'viewCountBeg': str(count_beg), 'viewLimit': str(per_page), 'offset': str(offset), 'dir': 'asc', 'order': 'zahlungsempfaenger', 'count': str(count), 'countBeg': str(count_beg), 'prevLimit': str(per_page), 'limit': str(per_page), 'seite': str(page) }) dom = response.dom() buttons = dom.xpath('.//button[@name="showBeg"]') args = [(x.attrib['value'], plz, page) for x in buttons] await self.schedule_many(self.detail, args) nav_text = dom.xpath('.//div[@id="listNavRight"]')[0].text_content() nav_text = nav_text.strip() + '|' print('%s lines for %s - now on page %d' % (count_beg, plz, page)) if 'von %d|' % page in nav_text: break page += 1 print('Going to page %d of %s' % (page, plz))