Skip to content

Commit 9492995

Browse files
committed
Trim attribute whitespace in XPath export
1 parent 480f277 commit 9492995

2 files changed

Lines changed: 3 additions & 3 deletions

File tree

autoscraper/auto_scraper.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -737,9 +737,9 @@ def _stack_to_xpath(stack):
737737
if not val:
738738
continue
739739
if isinstance(val, (list, tuple)):
740-
val = " ".join(str(v) for v in val)
740+
val = " ".join(str(v).strip() for v in val).strip()
741741
if isinstance(val, str):
742-
val = val
742+
val = val.strip()
743743

744744
if '"' in val and "'" in val:
745745
parts = val.split('"')

tests/unit/test_additional_features.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,4 @@ def test_get_rule_xpaths_preserves_spaces():
5555
scraper.build(html=html, wanted_list=["t"])
5656
rule_id = scraper.stack_list[0]["stack_id"]
5757
xpaths = scraper.get_rule_xpaths()
58-
assert xpaths[rule_id] == '/div[@style=" color: red; "][1]'
58+
assert xpaths[rule_id] == '/div[@style="color: red;"][1]'

0 commit comments

Comments
 (0)