parse an HTML in-memory document and build a tree.
770927
def htmlParseDoc(cur, encoding):
    
    ret = libxml2mod.htmlParseDoc(cur, encoding)
    if ret is None:raise parserError('htmlParseDoc() failed')
    return xmlDoc(_obj=ret)
295280
def from_file(cls, jss, filename):
        
        tree = ElementTree.parse(filename)
        root = tree.getroot()
        return cls(jss, root)
1231116
def parse_navigation_html_to_tree(html, id):
    
    def xpath(x):
        return html.xpath(x, namespaces=HTML_DOCUMENT_NAMESPACES)
    try:
        value = xpath('//*[@data-type="binding"]/@data-value')[0]
        is_translucent = value == 'translucent'
    except IndexError:
        is_translucent = False
    if is_translucent:
        id = TRANSLUCENT_BINDER_ID
    tree = {'id': id,
            'title': xpath('//*[@data-type="document-title"]/text()')[0],
            'contents': [x for x in _nav_to_tree(xpath('//xhtml:nav')[0])]
            }
    return tree
783371
function parse (node, self) {
  let block = false

  if (node.nodeType === 3) {
    let delimiters = self.templateDelimiters

    if (delimiters) {
      let tokens = parseTemplate(node.data, delimiters)

      if (tokens.length) {
        if (!(tokens.length === 1 && tokens[0].type === 0)) {
          tokens.forEach((token, i) => {
            let text = document.createTextNode(token.value)
            node.parentNode.insertBefore(text, node)

            if (token.type === 1) {
              self.buildBinding(TextBinding, text, null, token.value)
            }
          })

          node.parentNode.removeChild(node)
        }
      }
    }
  } else if (node.nodeType === 1) {
    block = self.traverse(node)
  }

  if (!block) {
    Array.prototype.slice.call(node.childNodes).forEach(function (node) { parse(node, self) })
  }
}
590031
def htmlReadDoc(cur, URL, encoding, options):
    
    ret = libxml2mod.htmlReadDoc(cur, URL, encoding, options)
    if ret is None:raise treeError('htmlReadDoc() failed')
    return xmlDoc(_obj=ret)
486684
def parse(self, xmp):
        """"""
        tree = etree.fromstring(xmp)
        rdf_tree = tree.find(RDF_NS + 'RDF')
        meta = defaultdict(dict)
        for desc in rdf_tree.findall(RDF_NS + 'Description'):
            for el in desc.getchildren():
                ns, tag = self._parse_tag(el)
                value = self._parse_value(el)
                meta[ns][tag] = value
        return dict(meta)
48144
function parse_html() {
      var reading_js = false, reading_css = false;
      var parser = new htmlparser.Parser({
        onopentag: function(name, attribs){
          if (name === "script" && ! attribs.src && (attribs.type === "text/javascript" || ! attribs.type)){
            reading_js = true;
          }
          else if (name === "style") {
            reading_css = true;
          }
        },
        ontext: function(text){
          if (reading_js) {
            scripts.push(text);
          }
          if (reading_css) {
            styles.push(text);
          }
        },
        onclosetag: function(tagname){
          if (tagname === "script"){
            reading_js = false;
          }
          else if (tagname === "style"){
            reading_css = false;
          }
        }
      });
      parser.write(src);
      parser.end();

      return true;
    }
224057
def parse_text(document, container, element):
    ""

    txt = None

    alternate = element.find(_name('{{{mc}}}AlternateContent'))

    if alternate is not None:
        parse_alternate(document, container, alternate)

    br = element.find(_name('{{{w}}}br'))

    if br is not None:
        if _name('{{{w}}}type') in br.attrib:
            _type = br.attrib[_name('{{{w}}}type')]
            brk = doc.Break(_type)
        else:
            brk = doc.Break()

        container.elements.append(brk)

    t = element.find(_name('{{{w}}}t'))

    if t is not None:
        txt = doc.Text(t.text)
        txt.parent = container

        container.elements.append(txt)

    rpr = element.find(_name('{{{w}}}rPr'))

    if rpr is not None:
        # Notice it is using txt as container
        parse_previous_properties(document, txt, rpr)

    for r in element.findall(_name('{{{w}}}r')):
        parse_text(document, container, r)

    foot = element.find(_name('{{{w}}}footnoteReference'))

    if foot is not None:
        parse_footnote(document, container, foot)

    end = element.find(_name('{{{w}}}endnoteReference'))

    if end is not None:
        parse_endnote(document, container, end)

    sym = element.find(_name('{{{w}}}sym'))

    if sym is not None:
        _font = sym.attrib[_name('{{{w}}}font')]
        _char = sym.attrib[_name('{{{w}}}char')]

        container.elements.append(doc.Symbol(font=_font, character=_char))

    image = element.find(_name('{{{w}}}drawing'))

    if image is not None:
        parse_drawing(document, container, image)

    refe = element.find(_name('{{{w}}}commentReference'))

    if refe is not None:
        _m = doc.Comment(refe.attrib[_name('{{{w}}}id')], 'reference')
        container.elements.append(_m)

    return
29487
def download(self):
		'''  '''

		self.page = requests.get(self.url)
		self.tree = html.fromstring(self.page.text)
844004
def build_base_document(dom, return_fragment=True):
    
    body_element = dom.find(".//body")

    if body_element is None:
        fragment = fragment_fromstring('<div id="readabilityBody"/>')
        fragment.append(dom)
    else:
        body_element.tag = "div"
        body_element.set("id", "readabilityBody")
        fragment = body_element

    return document_from_fragment(fragment, return_fragment)
842920
def parse_html(self, attr_string):
        """"""
        splitter = re.compile(self.split_regex(separator=self.spnl))
        attrs = splitter.split(attr_string)[1::2]

        idre = re.compile(r'''id=["']?([\w ]*)['"]?''')
        clsre = re.compile(r'''class=["']?([\w ]*)['"]?''')

        id_matches = [idre.search(a) for a in attrs]
        cls_matches = [clsre.search(a) for a in attrs]

        try:
            id = [m.groups()[0] for m in id_matches if m][0]
        except IndexError:
            id = ''

        classes = [m.groups()[0] for m in cls_matches if m][0].split()

        special = ['unnumbered' for a in attrs if '-' in a]
        classes.extend(special)

        kvs = [a.split('=', 1) for a in attrs if '=' in a]
        kvs = OrderedDict((k, v) for k, v in kvs if k not in ('id', 'class'))

        return id, classes, kvs
1242992
def main(argv=None):
    """"""
    parser = argparse.ArgumentParser(description=__doc__)
    parser.add_argument('collated_html', type=argparse.FileType('r'),
                        help='Path to the collated html'
                             ' file (use - for stdin)')
    parser.add_argument('-d', '--dump-tree', action='store_true',
                        help='Print out parsed model tree.')

    parser.add_argument('-o', '--output', type=argparse.FileType('w+'),
                        help='Write out epub of parsed tree.')

    parser.add_argument('-i', '--input', type=argparse.FileType('r'),
                        help='Read and copy resources/ for output epub.')

    args = parser.parse_args(argv)

    if args.input and args.output == sys.stdout:
        raise ValueError('Cannot output to stdout if reading resources')

    from cnxepub.collation import reconstitute
    binder = reconstitute(args.collated_html)

    if args.dump_tree:
        print(pformat(cnxepub.model_to_tree(binder)),
              file=sys.stdout)
    if args.output:
        cnxepub.adapters.make_epub(binder, args.output)

    if args.input:
        args.output.seek(0)
        zout = ZipFile(args.output, 'a', ZIP_DEFLATED)
        zin = ZipFile(args.input, 'r')
        for res in zin.namelist():
            if res.startswith('resources'):
                zres = zin.open(res)
                zi = zin.getinfo(res)
                zout.writestr(zi, zres.read(), ZIP_DEFLATED)
        zout.close()

    # TODO Check for documents that have no identifier.
    #      These should likely be composite-documents
    #      or the the metadata got wiped out.
    # docs = [x for x in cnxepub.flatten_to(binder, only_documents_filter)
    #         if x.ident_hash is None]

    return 0
953855
def from_xml(self, doc):
        """"""
        import xml.sax
        handler = DomainDumpParser(self)
        xml.sax.parse(doc, handler)
        return handler
1159938
def parse_html(infile, xpath):
    """"""
    if not isinstance(infile, lh.HtmlElement):
        infile = lh.fromstring(infile)
    infile = infile.xpath(xpath)
    if not infile:
        raise ValueError('XPath {0} returned no results.'.format(xpath))
    return infile
451595
def get_text_from_html(html):
  """"""

  try:
    soup = bs4.BeautifulSoup(html, "html.parser")
  except:  # pylint: disable=bare-except
    # Some docs don't parse
    return ""
  # Remove script and style tags
  for s in soup(["script", "style"]):
    s.decompose()
  return "\n".join([s for s in _soup_strings(soup)])
491063
def parse(cls, root):
        
        if root.tag != utils.lxmlns("mets") + "mdWrap":
            raise exceptions.ParseError(
                "MDWrap can only parse mdWrap elements with METS namespace."
            )
        mdtype = root.get("MDTYPE")
        if not mdtype:
            raise exceptions.ParseError("mdWrap must have a MDTYPE")
        othermdtype = root.get("OTHERMDTYPE")
        document = root.xpath("mets:xmlData/*", namespaces=utils.NAMESPACES)
        if len(document) == 0:
            raise exceptions.ParseError(
                "All mdWrap/xmlData elements must have at least one child; this"
                " one has none"
            )
        elif len(document) == 1:
            document = document[0]

        # Create a copy, so that the element is not moved by duplicate references.
        document = copy.deepcopy(document)

        return cls(document, mdtype, othermdtype)
1317849
def htmlCreateMemoryParserCtxt(buffer, size):
    
    ret = libxml2mod.htmlCreateMemoryParserCtxt(buffer, size)
    if ret is None:raise parserError('htmlCreateMemoryParserCtxt() failed')
    return parserCtxt(_obj=ret)