0

I have the following HTML

<div class="detailSection">
            <span>Authorized Person(s) Detail</span>
            <span>
                     <b>Name &amp; Address</b>
            </span>
            <br>
            <br>
            <span>Title&nbsp;MGR</span>
            <br>
            <br>
            "
            EYN, KHASHY    "   
            <span>

               <div>
               100 Wall Street<br>
               NEW YORK, NY 10005<br>
               </div>
    
            </span>
            <br>
            </div>

I would like to extract the EYN, KHASHY portion of the HTML. My Chrome developer tools tells me this is a #text node(?) and I think that is why it is not working with my current code. Although I am not familiar with #text nodes at all but it seems distinct from the HTML.

Currently my code selects all children elements of the <div> which is parent to the #text. As follows:

 persons = driver.find_element_by_xpath('//*[@id="maincontent"]/div[2]/div[6]')
        all_children = persons.find_elements_by_xpath(".//*")
        for child in all_children:
            li_person.append(child.text)
            print(child.text)

This gives me all the text except the EYN, KHASHY. Probably because all other text is part of a certain element as Chrome dev tools tell me when I hover over. The #text "EYN, KHASHY" returns as blank.

How can I select this node and extract this information?

2
  • If "persons" is the parent <div> block, then what you want is persons.text. That text is not in a child tag, it is the text of that tag. Commented May 4, 2021 at 18:10
  • Omg I can't believe I overlooked that. Thank you. Please post as an answer so I may mark it as answered. Commented May 4, 2021 at 18:24

1 Answer 1

1

If "persons" is the parent <div> block, then what you want is persons.text. That text is not in a child tag, it is the text of that tag

Sign up to request clarification or add additional context in comments.

Comments

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.