def rex_search(self, regexp, flags=0, byte=False, default=NULL): """ Search the regular expression in response body. :param byte: if False then search is performed in `response.unicode_body()` else the rex is searched in `response.body`. Note: if you use default non-byte mode than do not forget to build your regular expression with re.U flag. Return found match object or None """ regexp = normalize_regexp(regexp, flags) match = None if byte: if not isinstance(regexp.pattern, six.text_type) or not six.PY3: # if six.PY3: # body = self.body_as_bytes() # else: # body = self.body match = regexp.search(self.body) else: if isinstance(regexp.pattern, six.text_type) or not six.PY3: ubody = self.unicode_body() match = regexp.search(ubody) if match: return match else: if default is NULL: raise DataNotFound('Could not find regexp: %s' % regexp) else: return default
def rex(self, regexp, flags=0): norm_regexp = rex_tools.normalize_regexp(regexp, flags) matches = list(norm_regexp.finditer(self.html())) return RexResultList(matches, source_rex=norm_regexp)