0

I have following html code:

<div class="test">
    "Test"
    <br>
    <script type="text/javascript"></script>
    <a href="mailto:[email protected]">[email protected]</a> 
    " "
</div>

How to get the email address from this code using lxml?

1 Answer 1

4
import lxml.html as LH
text='''\
<div class="test">
    "Test"
    <br>
    <script type="text/javascript"></script>
    <a href="mailto:[email protected]">[email protected]</a> 
    " "
</div>
'''

doc=LH.fromstring(text)
print(doc.xpath('//a[starts-with(@href,"mailto:")]/text()')[0])
# [email protected]
Sign up to request clarification or add additional context in comments.

2 Comments

<div class="test"> "Test" <br> <script type="text/javascript"></script> <a href="mailto:[email protected]">[email protected]</a> " " </div> - it necessarily?
No, it's only used to provide an input for the function. You'll have to replace text with whatever you keep the HTML in.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.