Parses the DOM and returns character attributes in the main-content area.

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

    :rtype: dict
    :return: Character attributes.
540500
def parse(self, character_page):
    
    character_info = self.parse_sidebar(character_page)

    second_col = character_page.find(u'div', {'id': 'content'}).find(u'table').find(u'tr').find_all(u'td', recursive=False)[1]
    name_elt = second_col.find(u'div', {'class': 'normal_header'})

    try:
      name_jpn_node = name_elt.find(u'small')
      if name_jpn_node:
        character_info[u'name_jpn'] = name_jpn_node.text[1:-1]
      else:
        character_info[u'name_jpn'] = None
    except:
      if not self.session.suppress_parse_exceptions:
        raise

    try:
      name_elt.find(u'span').extract()
      character_info[u'name'] = name_elt.text.rstrip()
    except:
      if not self.session.suppress_parse_exceptions:
        raise

    try:
      description_elts = []
      curr_elt = name_elt.nextSibling
      while True:
        if curr_elt.name not in [None, u'br']:
          break
        description_elts.append(unicode(curr_elt))
        curr_elt = curr_elt.nextSibling
      character_info[u'description'] = ''.join(description_elts)
    except:
      if not self.session.suppress_parse_exceptions:
        raise

    try:
      character_info[u'voice_actors'] = {}
      voice_actors_header = second_col.find(u'div', text=u'Voice Actors')
      if voice_actors_header:
        voice_actors_table = voice_actors_header.find_next_sibling(u'table')
        for row in voice_actors_table.find_all(u'tr'):
          # second column has va info.
          info_col = row.find_all(u'td')[1]
          voice_actor_link = info_col.find(u'a')
          name = ' '.join(reversed(voice_actor_link.text.split(u', ')))
          link_parts = voice_actor_link.get(u'href').split(u'/')
          # of the form: /people/82/Romi_Park
          person = self.session.person(int(link_parts[2])).set({'name': name})
          language = info_col.find(u'small').text
          character_info[u'voice_actors'][person] = language
    except:
      if not self.session.suppress_parse_exceptions:
        raise

    return character_info
1015261
def _get_codepage_char_map(self, encoding):
        
        # Skip things that were loaded previously
        if encoding in self.available_characters:
            return self.available_characters[encoding]
        codepage_char_list = self._get_codepage_char_list(encoding)
        codepage_char_map = dict((utf8, i + 128) for (i, utf8) in enumerate(codepage_char_list))
        self.available_characters[encoding] = codepage_char_map
        return codepage_char_map
194176
def html(self):
    '''
    
    '''

    if not getattr(self, '_html', False):
      query_params = {
        'prop': 'revisions',
        'rvprop': 'content',
        'rvlimit': 1,
        'rvparse': '',
        'titles': self.title
      }

      request = _wiki_request(query_params)
      self._html = request['query']['pages'][self.pageid]['revisions'][0]['*']

    return self._html
479763
def get_page_from_string_or_id(page_string, lang=None):
    """"""
    if type(page_string) == int:
        return Page.objects.get(pk=int(page_string))
    # if we have a string coming from some templates templates
    if (isinstance(page_string, SafeText) or
            isinstance(page_string, str)):
        if page_string.isdigit():
            return Page.objects.get(pk=int(page_string))
        return Page.objects.from_path(page_string, lang)
    # in any other case we return the input becasue it's probably
    # a Page object.
    return page_string
916946
def get_title(page):
  
  start_pos = page.find("<title>")
  end_pos = page.find("</title>")
  assert start_pos != -1
  assert end_pos != -1
  start_pos += len("<title>")
  return text_encoder.to_unicode_utf8(page[start_pos:end_pos])
1354892
def character_span(self):
        
        begin, end = self.token_span
        return (self.sentence[begin].character_span[0], self.sentence[end-1].character_span[-1])
106882
def _parse_search_result_html(self, doc):
        
        result = []
        soup = bs4.BeautifulSoup(doc, 'lxml')
        search_item_div_list = soup.select(
            '.search-result > ul > li > .search-item')
        if not search_item_div_list:
            return []
        for item in search_item_div_list:
            subinfo = {
                'title': '',
                'link': '',
                'author': 'zimuzu',
                'exts': [],
                'languages': [],
                'rate': 0,
                'download_count': 0,
            }
            a = item.find('a')
            if not a:
                continue
            url = a.get('href')
            subinfo['link'] = self._join_url(self.API, url)
            zh_title = a.get_text()
            for k, v in self.LANGUAGES_MAP.items():
                if k in zh_title:
                    subinfo['languages'].append(v)
            font = item.find('font', class_="f4")
            en_title = font.string
            subinfo['title'] = en_title
            result.append(subinfo)
        return result
944357
def _parse_search_results_html(self, doc):
        
        subgroups = []
        soup = bs4.BeautifulSoup(doc, 'lxml')
        ele_divs = soup.select('div.item.prel')
        if not ele_divs:
            return subgroups
        for item in ele_divs:
            ele_a = item.select('p.tt > a')
            if not ele_a:
                continue
            link = ele_a[0].get('href')
            title = ele_a[0].get_text().strip()
            subgroups.append({
                'title': title,
                'link': link,
            })
        return subgroups
580540
def _page_to_text(page):
  
  # text start tag looks like "<text ..otherstuff>"
  start_pos = page.find(u"<text")
  assert start_pos != -1
  end_tag_pos = page.find(u">", start_pos)
  assert end_tag_pos != -1
  end_tag_pos += len(u">")
  end_pos = page.find(u"</text>")
  if end_pos == -1:
    return u""
  return page[end_tag_pos:end_pos]
1224462
def get_elements_attributes(parent_to_parse, element_path=None, attrib_name=None):
    

    attrs = _get_elements_property(parent_to_parse, element_path, 'attrib')

    if not attrib_name:
        return attrs

    return [attr[attrib_name] for attr in attrs if attrib_name in attr]
1029842
def html(self, unicode=False):
        
        html = lxml.html.tostring(self.element, encoding=self.encoding)
        if unicode:
            html = html.decode(self.encoding)
        return html
850634
def parse_html(html: str, parser: FragmentParser = None) -> Node:
    
    parser = parser or FragmentParser()
    parser.feed(html)
    return parser.root
319773
def _parse_page(self, query):
        
        args = {k[5:-1]: v for k, v in query.items() if k.startswith('page[')}

        if {'number', 'size'} == set(args.keys()):
            if not args['number'].isdecimal() or not args['size'].isdecimal():
                raise BadRequestError('Page query parameters must be integers')

            number = int(args['number'])
            size = int(args['size'])
            start = number * size

            return start, start + size - 1

        if {'limit', 'offset'} == set(args.keys()):
            if not args['limit'].isdecimal() or not args['offset'].isdecimal():
                raise BadRequestError('Page query parameters must be integers')

            limit = int(args['limit'])
            offset = int(args['offset'])

            return offset, offset + limit - 1

        return 0, None
729304
def get_soup(page=''):
    
    content = requests.get('%s/%s' % (BASE_URL, page)).text
    return BeautifulSoup(content)
510401
def page_str(self):
        
        tmpl = '.. _%s:\n\n%s\n\n%s\n\n----\n\n%s'
        components = (
            self._ms_name, self._page_title, self._intro_text,
            self._member_defs
        )
        return tmpl % components
822796
def page_from_file(input_file):
    
    #  print("PARSING PARSING '%s'" % input_file)
    if input_file.mimetype.startswith('image'):
        return page_from_image(input_file)
    if input_file.mimetype == MIMETYPE_PAGE:
        return parse(input_file.local_filename, silence=True)
    raise Exception("Unsupported mimetype '%s'" % input_file.mimetype)
591264
def parse(node, default_paragraph, default_character)
      node.xpath('*').each do |pg_size_subnode|
        case pg_size_subnode.name
        when 'pgSz'
          @size = PageSize.new.parse(pg_size_subnode)
        when 'pgBorders'
          page_borders = Borders.new
          page_borders.display = pg_size_subnode.attribute('display').value.to_sym unless pg_size_subnode.attribute('display').nil?
          page_borders.offset_from = pg_size_subnode.attribute('offsetFrom').value.to_sym unless pg_size_subnode.attribute('offsetFrom').nil?
          pg_size_subnode.xpath('w:bottom').each do |bottom|
            page_borders.bottom = BordersProperties.new(parent: page_borders).parse(bottom)
          end
          pg_size_subnode.xpath('w:left').each do |left|
            page_borders.bottom = BordersProperties.new(parent: page_borders).parse(left)
          end
          pg_size_subnode.xpath('w:top').each do |top|
            page_borders.bottom = BordersProperties.new(parent: page_borders).parse(top)
          end
          pg_size_subnode.xpath('w:right').each do |right|
            page_borders.bottom = BordersProperties.new(parent: page_borders).parse(right)
          end
          @page_borders = page_borders
        when 'type'
          @type = pg_size_subnode.attribute('val').value
        when 'pgMar'
          @margins = PageMargins.new(parent: self).parse(pg_size_subnode)
        when 'pgNumType'
          @num_type = pg_size_subnode.attribute('fmt').value unless pg_size_subnode.attribute('fmt').nil?
        when 'formProt'
          @form_prot = pg_size_subnode.attribute('val').value
        when 'textDirection'
          @text_direction = pg_size_subnode.attribute('val').value
        when 'docGrid'
          @document_grid = DocumentGrid.new(parent: self).parse(pg_size_subnode)
        when 'titlePg'
          @title_page = option_enabled?(pg_size_subnode)
        when 'cols'
          @columns = Columns.new.parse(pg_size_subnode)
        when 'headerReference', 'footerReference'
          target = OOXMLDocumentObject.get_link_from_rels(pg_size_subnode.attribute('id').value)
          OOXMLDocumentObject.add_to_xmls_stack("word/#{target}")
          note = Note.parse(default_paragraph: default_paragraph,
                            default_character: default_character,
                            target: target,
                            assigned_to: pg_size_subnode.attribute('type').value,
                            type: File.basename(target).sub('.xml', ''),
                            parent: self)
          @notes << note
          OOXMLDocumentObject.xmls_stack.pop
        when 'footnotePr'
          @footnote_properties = FootnoteProperties.new(parent: self).parse(pg_size_subnode)
        end
      end
      self
    end