MCPcopy
hub / github.com/pandas-dev/pandas / _build_xpath_expr

Function _build_xpath_expr

pandas/io/html.py:675–695  ·  view source on GitHub ↗

Build an xpath expression to simulate bs4's ability to pass in kwargs to search for attributes when using the lxml parser. Parameters ---------- attrs : dict A dict of HTML attributes. These are NOT checked for validity. Returns ------- expr : unicode

(attrs)

Source from the content-addressed store, hash-verified

673
674
675def _build_xpath_expr(attrs) -> str:
676 """
677 Build an xpath expression to simulate bs4's ability to pass in kwargs to
678 search for attributes when using the lxml parser.
679
680 Parameters
681 ----------
682 attrs : dict
683 A dict of HTML attributes. These are NOT checked for validity.
684
685 Returns
686 -------
687 expr : unicode
688 An XPath expression that checks for the given HTML attributes.
689 """
690 # give class attribute as class_ because class is a python keyword
691 if "class_" in attrs:
692 attrs["class"] = attrs.pop("class_")
693
694 s = " and ".join([f"@{k}={v!r}" for k, v in attrs.items()])
695 return f"[{s}]"
696
697
698_re_namespace = {"re": "http://exslt.org/regular-expressions"}

Callers 1

_parse_tablesMethod · 0.85

Calls 3

popMethod · 0.45
joinMethod · 0.45
itemsMethod · 0.45

Tested by

no test coverage detected