Parses the DOM and returns character favorites attributes.

    :type favorites_page: :class:`bs4.BeautifulSoup`
    :param favorites_page: MAL character favorites page's DOM

    :rtype: dict
    :return: Character favorites attributes.
195829
def parse_favorites(self, favorites_page):
    
    character_info = self.parse_sidebar(favorites_page)
    second_col = favorites_page.find(u'div', {'id': 'content'}).find(u'table').find(u'tr').find_all(u'td', recursive=False)[1]

    try:
      character_info[u'favorites'] = []
      favorite_links = second_col.find_all('a', recursive=False)
      for link in favorite_links:
        # of the form /profile/shaldengeki
        character_info[u'favorites'].append(self.session.user(username=link.text))
    except:
      if not self.session.suppress_parse_exceptions:
        raise

    return character_info
1291860
def parse_stats(self, media_page):
    
    media_info = self.parse_sidebar(media_page)
    verb_progressive = self.consuming_verb + u'ing'
    status_stats = {
      verb_progressive: 0,
      'completed': 0,
      'on_hold': 0,
      'dropped': 0,
      'plan_to_' + self.consuming_verb: 0
    }
    try:
      consuming_elt = media_page.find(u'span', {'class': 'dark_text'}, text=verb_progressive.capitalize())
      if consuming_elt:
        status_stats[verb_progressive] = int(consuming_elt.nextSibling.strip().replace(u',', ''))
    except:
      if not self.session.suppress_parse_exceptions:
        raise

    try:
      completed_elt = media_page.find(u'span', {'class': 'dark_text'}, text="Completed:")
      if completed_elt:
        status_stats[u'completed'] = int(completed_elt.nextSibling.strip().replace(u',', ''))
    except:
      if not self.session.suppress_parse_exceptions:
        raise

    try:
      on_hold_elt = media_page.find(u'span', {'class': 'dark_text'}, text="On-Hold:")
      if on_hold_elt:
        status_stats[u'on_hold'] = int(on_hold_elt.nextSibling.strip().replace(u',', ''))
    except:
      if not self.session.suppress_parse_exceptions:
        raise

    try:
      dropped_elt = media_page.find(u'span', {'class': 'dark_text'}, text="Dropped:")
      if dropped_elt:
        status_stats[u'dropped'] = int(dropped_elt.nextSibling.strip().replace(u',', ''))
    except:
      if not self.session.suppress_parse_exceptions:
        raise

    try:
      planning_elt = media_page.find(u'span', {'class': 'dark_text'}, text="Plan to " + self.consuming_verb.capitalize() + ":")
      if planning_elt:
        status_stats[u'plan_to_' + self.consuming_verb] = int(planning_elt.nextSibling.strip().replace(u',', ''))
    except:
      if not self.session.suppress_parse_exceptions:
        raise

    media_info[u'status_stats'] = status_stats

    score_stats = {
      1: 0,
      2: 0,
      3: 0,
      4: 0,
      5: 0,
      6: 0,
      7: 0,
      8: 0,
      9: 0,
      10: 0
    }
    try:
      score_stats_header = media_page.find(u'h2', text='Score Stats')
      if score_stats_header:
        score_stats_table = score_stats_header.find_next_sibling(u'table')
        if score_stats_table:
          score_stats = {}
          score_rows = score_stats_table.find_all(u'tr')
          for i in xrange(len(score_rows)):
            score_value = int(score_rows[i].find(u'td').text)
            score_stats[score_value] = int(score_rows[i].find(u'small').text.replace(u'(u', '').replace(u' votes)', ''))
    except:
      if not self.session.suppress_parse_exceptions:
        raise

    media_info[u'score_stats'] = score_stats

    return media_info
172969
def get_pages(url):
    
    while True:
        yield url
        doc = html.parse(url).find("body")
        links = [a for a in doc.findall(".//a") if a.text and a.text.startswith("next ")]
        if not links:
            break
        url = urljoin(url, links[0].get('href'))
70156
def load_stats(self):
    
    stats_page = self.session.session.get(u'http://myanimelist.net/' + self.__class__.__name__.lower() + u'/' + str(self.id) + u'/' + utilities.urlencode(self.title) + u'/stats').text
    self.set(self.parse_stats(utilities.get_clean_dom(stats_page)))
    return self
60115
def _get_page_title(self, page):
        
        fname = os.path.join(SOURCE_PATH, '{}.rst'.format(page))
        option_parser = docutils.frontend.OptionParser(
            components=(docutils.parsers.rst.Parser,))
        doc = docutils.utils.new_document(
            '<doc>',
            option_parser.get_default_values())
        with open(fname) as f:
            data = f.read()

        parser = docutils.parsers.rst.Parser()
        # do not generate any warning when parsing the rst
        with open(os.devnull, 'a') as f:
            doc.reporter.stream = f
            parser.parse(data, doc)

        section = next(node for node in doc.children
                       if isinstance(node, docutils.nodes.section))
        title = next(node for node in section.children
                     if isinstance(node, docutils.nodes.title))

        return title.astext()
1241587
def _get_max_page(dom):
    
    div = dom.find("div", {"class": "razeniKnihListovani"})

    if not div:
        return 1

    # isolate only page numbers from links
    links = div[0].find("a")
    max_page = filter(
        lambda x: "href" in x.params and "pageindex=" in x.params["href"],
        links
    )
    max_page = map(
        lambda x: x.params["href"].split("pageindex=")[-1],
        max_page
    )
    max_page = filter(lambda x: x.isdigit(), max_page)
    max_page = map(lambda x: int(x), max_page)

    if not max_page:
        return 1

    return max(max_page)
651888
def _parse(self):
        
        # Is this a shorthand template?
        if self._element.tag == 'template':
            return self._parse_template(self._element)

        # Is this a shorthand redirect?
        if self._element.tag == 'redirect':
            return self._parse_redirect(self._element)

        for child in self._element:
            method_name = '_parse_' + child.tag

            if hasattr(self, method_name):
                parse = getattr(self, method_name)
                parse(child)
941730
def _get_results(self, page):
		""""""

		soup = _get_soup(page)
		details = soup.find_all("tr", class_="odd")
		even = soup.find_all("tr", class_="even")
		# Join the results
		for i in range(len(even)):
			details.insert((i * 2)+1, even[i])

		return self._parse_details(details)
197384
def parse(self, media_page):
    
    media_info = self.parse_sidebar(media_page)

    try:
      synopsis_elt = media_page.find(u'h2', text=u'Synopsis').parent
      utilities.extract_tags(synopsis_elt.find_all(u'h2'))
      media_info[u'synopsis'] = synopsis_elt.text.strip()
    except:
      if not self.session.suppress_parse_exceptions:
        raise

    try:
      related_title = media_page.find(u'h2', text=u'Related ' + self.__class__.__name__)
      if related_title:
        related_elt = related_title.parent
        utilities.extract_tags(related_elt.find_all(u'h2'))
        related = {}
        for link in related_elt.find_all(u'a'):
          href = link.get(u'href').replace(u'http://myanimelist.net', '')
          if not re.match(r'/(anime|manga)', href):
            break
          curr_elt = link.previous_sibling
          if curr_elt is None:
            # we've reached the end of the list.
            break
          related_type = None
          while True:
            if not curr_elt:
              raise MalformedAnimePageError(self.id, related_elt, message="Prematurely reached end of related anime listing")
            if isinstance(curr_elt, bs4.NavigableString):
              type_match = re.match(u'(?P<type>[a-zA-Z\ \-]+):', curr_elt)
              if type_match:
                related_type = type_match.group(u'type')
                break
            curr_elt = curr_elt.previous_sibling
          title = link.text
          # parse link: may be manga or anime.
          href_parts = href.split(u'/')
          # sometimes links on MAL are broken, of the form /anime//
          if href_parts[2] == '':
            continue
          # of the form: /(anime|manga)/1/Cowboy_Bebop
          obj_id = int(href_parts[2])
          new_obj = getattr(self.session, href_parts[1])(obj_id).set({'title': title})
          if related_type not in related:
            related[related_type] = [new_obj]
          else:
            related[related_type].append(new_obj)
        media_info[u'related'] = related
      else:
        media_info[u'related'] = None
    except:
      if not self.session.suppress_parse_exceptions:
        raise

    return media_info
795723
def get_page_tags(page):
    
    from .models import PageTags
    try:
        return page.pagetags.tags.all()
    except PageTags.DoesNotExist:
        return []
1304837
def get_template_from_request(request, page=None):
    
    page_templates = settings.get_page_templates()
    if len(page_templates) == 0:
        return settings.PAGE_DEFAULT_TEMPLATE
    template = request.REQUEST.get('template', None)
    if template is not None and \
            (template in dict(page_templates).keys() or
            template == settings.PAGE_DEFAULT_TEMPLATE):
        return template
    if page is not None:
        return page.get_template()
    return settings.PAGE_DEFAULT_TEMPLATE
593028
def findRelMe(sourceURL):
    
    r = requests.get(sourceURL)
    result = {'status':  r.status_code,
              'headers': r.headers,
              'history': r.history,
              'content': r.text,
              'relme':   [],
              'url':     sourceURL
              }
    if r.status_code == requests.codes.ok:
        dom = BeautifulSoup(r.text, _html_parser)
        for link in dom.find_all('a', rel='me'):
            rel  = link.get('rel')
            href = link.get('href')
            if rel is not None and href is not None:
                url = urlparse(href)
                if url is not None and url.scheme in ('http', 'https'):
                    result['relme'].append(cleanURL(href))
    return result
203271
def parsed(self):
        
        return BeautifulSoup(
            self.response.content,
            features=self.browser.parser,
        )
1046690
def load(self):
    
    character = self.session.session.get(u'http://myanimelist.net/character/' + str(self.id)).text
    self.set(self.parse(utilities.get_clean_dom(character)))
    return self
735186
def get_page_text(self, page):
        
        url = self.get_page_text_url(page)
        return self._get_url(url)
1020143
def rel_links(cls, page):
    """"""
    for match in cls.REL_RE.finditer(page):
      href, rel = match.group(0), match.group(1)
      if rel not in cls.REL_TYPES:
        continue
      href_match = cls.HREF_RE.search(href)
      if href_match:
        href = cls.href_match_to_url(href_match)
        parsed_href = urlparse(href)
        if any(parsed_href.path.endswith(ext) for ext in cls.REL_SKIP_EXTENSIONS):
          continue
        yield href
552278
function parsePage(book, page) {
    var fs = book.getContentFS();
    var file = page.getFile();

    return fs.readAsString(file.getPath())
    .then(function(content) {
        return parsePageFromString(page, content);
    });
}