Home > Blockchain >  Python - Getting text using selenium that has no label
Python - Getting text using selenium that has no label

Time:07-18

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:

https://i.stack.imgur.com/1KwMr.png

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.

Any help is appreciated :)

CodePudding user response:

This is how you can get the text in question:

from bs4 import BeautifulSoup
html = '''
    <div ><div>some text</div><div ></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.

CodePudding user response:

you can scrap element By XPATH

could you consider giving mkt-kard you scrapped like a text and type, you should extract the text using regex

  • Related