If you are only finding weight
, I would suggest you to only check if the keyword "weight" is in the p
tag. Also, if you use find
, it would only return the first result - so if the first p
tag is not "Weight", you would not be able to find it.
Also, if your class name is product__description__text
, you should also change your finding class name to product__description__text
.
results = soup.find_all('div', attrs={'class':'product__description__text'})
Weight_L = []
for result in results:
p_tags = result.find_all('p', attrs={'dir':'ltr'})
for tag in p_tags:
if "Weight:" in tag.text:
weight = tag.text
Weight_L.append(weight)
If the above code you posted is soup
, the result would be: ['Weight: 16.5 pounds']
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…