def set_input_by_number(self, number, value): """ Set the value of form element by its number in the form :param number: number of element :param value: value which should be set to element """ sel = XpathSelector(self.form) elem = sel.select('.//input[@type="text"]')[number].node() return self.set_input(elem.get('name'), value)
def set_input_by_id(self, _id, value): """ Set the value of form element by its `id` attribute. :param _id: id of element :param value: value which should be set to element """ xpath = './/*[@id="%s"]' % _id if self._lxml_form is None: self.choose_form_by_element(xpath) sel = XpathSelector(self.form) elem = sel.select(xpath).node() return self.set_input(elem.get('name'), value)
def get_prices(self, grab, subject): """Parsing information about Obligatory extras and Optional extras for objects are prices and optional""" prices = [] try: extras = grab.doc.rex_text( '<h3 class\="h6 copy-sp-m">.*?%s.*?</h3>(.+?)</ul>' % subject, flags=re.S) except DataNotFound: logging.debug("Price %s is not found on %s" % (subject, grab.doc.url)) return None sel = XpathSelector(fromstring(extras)) prices = [] for li in sel.select('//li[@class="list__item u-cf"]'): obligatory = OrderedDict() obligatory['name'] = li.select('node()').text() money = li.select('node()/strong').text() obligatory['value'] = money[1:].replace(',', '') # Find perweek or perday if li.select('span[@class="boatview__extras-amount"' + ' and contains(text(),"per week")]').exists(): obligatory['perweek'] = True elif li.select('span[@class="boatview__extras-amount"' + ' and contains(text(),"per day")]').exists(): obligatory['perday'] = True obligatory['currency'] = money[0] prices.append(obligatory) if len(prices) < 1: logging.debug("Price %s contains less than one element on: %s" % (subject, grab.doc.url)) return None return prices
def select(self, xpath): sel = XpathSelector(self.dom_tree) return sel.select(xpath)