I am looking for an exact match. In the example below, if
searching for a span with text "Chocolate", I only want ONE result.
Example:
<span class="x">
Chocolate
</span>
<span class="x">
Chocolate Bar
</span>
I need the span Tag as a return value because ultimately I am
interested in this tag's siblings, not the text itself.
I played around with
x = soup('span', text=re.compile("Chocolate"))
x[0].parent ...
but this gives me multiple hits (tags containing "Chocolate" +
"Chocolate Bar").
--
Best Regards,
Tarlika Elisabeth Schmitz
You should read a bit about regular expressions. Specifically, the
documentation of the Python re module isn't too bad:
http://docs.python.org/library/re.html#regular-expression-syntax
In your case, try:
re.compile(r"^Chocolate$")
- Tal Einat
>Tarlika Elisabeth Schmitz wrote:
>> I am looking for an exact match. In the example below, if
>> searching for a span with text "Chocolate", I only want ONE result.
>>
>> Example:
>>
>> <span class="x">
>> Chocolate
>> </span>
>> <span class="x">
>> Chocolate Bar
>> </span>
>>
>> [...]
>
>In your case, try:
>re.compile(r"^Chocolate$")
re.compile(r"^ *Chocolate *$", re.MULTILINE)
does the job