#๐Ÿ”’ Sanitizing xpath string

4 messages ยท Page 1 of 1 (latest)

sour pagoda
#

I'm running into trouble with using xpath to find elements/nodes, particularly due to a sanitization problem.

An element I am trying to manually locate for this problem:

<h2>
<span class="mw-headline" id="030:_&quot;Harpie's_Pet_Dragon&quot;">030: "Harpie's Pet Dragon"</span>
</h2>

I'm trying to do this a couple different ways:

xpath("//span[@id='030:_Harpie\'s_Pet_Dragon']")
xpath("//span[@id=\"030:_\"Harpie's_Pet_Dragon\"\"]")

They all return:

Traceback (most recent call last):
  File "<input>", line 1, in <module>
    x.xpath("//span[@id=\"030:_\"Harpie's_Pet_Dragon\"\"]")
  File "src/lxml/etree.pyx", line 1623, in lxml.etree._Element.xpath
  File "src/lxml/xpath.pxi", line 290, in lxml.etree.XPathElementEvaluator.__call__
  File "src/lxml/xpath.pxi", line 210, in lxml.etree._XPathEvaluatorBase._handle_result
lxml.etree.XPathEvalError: Invalid predicate
ripe mangoBOT
#

@sour pagoda

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

ripe mangoBOT
#

@sour pagoda

Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.