Hello I am scraping a website using selenium which has a button named view profile whenever i scrape it shows me the text of button in my output because it’s under the same <div>
that I am scraping data from like
JavaScript
x
4
1
<div class="results">
2
<p>example</p>
3
<a href="www.example.com" rel="nofollow" class="search-result__button button button_s">View Profile</a>
4
my code
JavaScript
1
4
1
for pp in driver.find_elements_by_class_name('results'):
2
print(pp.text)
3
print('***********************')
4
its ouput
JavaScript
1
7
1
example text
2
example text
3
view profile
4
******************
5
example text
6
7
Is there any way I can remove that view profile text or stop it from printing?
Thanks
Advertisement
Answer
You can get the text of the button alone and remove it
JavaScript
1
5
1
for pp in driver.find_elements_by_class_name('results'):
2
button_text = pp.find_element_by_class_name('search-result__button').text
3
text = pp.text.replace(button_text, '')
4
print(text)
5