I am using a Python script to extract information from a website using Selenium library. Using some selector, I got a WebElement object of the target element I am after which looks something like the following:
<myTargetElement><strong>324. </strong>Some interesting content that might contain numbers 323 or dots ...,;</myTargetElement>
I want to extract two pieces of information in separate:
The Id surrounded by the strong
tag, and I've done this as following:
myTargetElementObject.find_element_by_tag_name('strong').text.strip(' .')
Now I am puzzled how to extract the other part. If I used myTargetElementObject.text
, it will return the id within the text.
The data I am extracting is very big and I am cautious about using regex. Is there a way using WebElement object to return the text of the element without the sub-elements?