T
T
tigervvin2022-01-18 14:59:44
Python
tigervvin, 2022-01-18 14:59:44

Selenium Python how to get tags with content that is in a tag?

Hello!!! I encountered such a problem when parsing, well, I don’t know all the functionality of Selenium.

<div class="main">
    <div class="wrapper">Содержимое тэга</div>
    <div class="class">Содержимое тэга</div>
</div>

I get to the div class="main" tag using the xPath method, since there are still a lot of tags above, it doesn't work any other way, I want to get this answer:
<div class="wrapper">Содержимое тэга 1</div>
<div class="class">Содержимое тэга 2</div>

If you write the following
driver.find_element_by_xpath("//body//div//div[@class='main']").text

I just get:
Content of tag 1
Content of tag 2
Need an answer with tags

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Karbivnichy, 2022-01-18
@tigervvin

Maybe so:

driver.find_element_by_xpath("//body//div//div[@class='main']").get_attribute('innerHTML')

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question