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)
| 673 | |
| 674 | |
| 675 | def _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"} |
no test coverage detected