1

I'm trying to scrape some information from a website using Selenium and Python and sometimes there's texts like this HZS stonks remaining... that does not have any name or label that I can get the text by:

snapshot

I can get the mkt-card class element easily and I assume that I can somehow get it from the mkt-card element but I can't figure out how to do it.

0

2 Answers 2

1

This is how you can get the text in question:

from bs4 import BeautifulSoup
html = '''
    <div class="mkt-card"><div>some text</div><div class="error"></div>"HZS stonks remaining 0.14"</div>
'''
soup = BeautifulSoup(html, 'html.parser')
stonks_text = soup.select_one('div.error').next_sibling
print(stonks_text)

This returns "HZS stonks remaining 0.14"

Next time do not post screenshots, but actual text.

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

Comments

0

As per the HTML:

snapshot

the desired element is within a text node and is within it's parent element <div class="mkt-card">


Solution

To print the text HZS stonks remaining 0.14 you can use either of the following locator strategies:

  • Using css_selector`:

    print(driver.find_element(By.CSS_SELECTOR, "div.mkt-card").text)
    
  • Using xpath:

    print(driver.find_element(By.XPATH, "//div[@class='mkt-card']").text)
    

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.