Reputation: 47
I want to get the text I want mention in here within the a class tag
<a class="_2cLu-l" title="Realme 5 (Crystal Blue, 32 GB)" target="_blank" rel="noopener noreferrer" href="/realme-5-crystal-blue-32-gb/p/itmfj9twbwfznhyk?pid=MOBFJ9TWENA2FSGX&lid=LSTMOBFJ9TWENA2FSGXSV98FT&marketplace=FLIPKART&srno=s_1_3&otracker=search&otracker1=search&fm=organic&iid=ddea8cef-acd0-4f05-a786-608404d850de.MOBFJ9TWENA2FSGX.SEARCH&ppt=sp&ppn=sp&ssid=xagdh1n18g0000001568504585590&qH=f7a42fe7211f98ac">TEXT I WANT</a>
I have tried with the following statement
for a in soup.findAll('a',href=True, attrs={'class':'_2cLu-l'}):
name=a.find('a', attrs={'class':'_2cLu-l'})
print(name)
name.text
Upvotes: 0
Views: 71
Reputation: 4763
This code worked for me to solve your test case.
from bs4 import BeautifulSoup
soup = BeautifulSoup('your html',"html.parser")
a = soup.findAll('a',text=True, attrs={'class':'_2cLu-l'})
for item in a:
print(item.text)
Upvotes: 1