[英]I want span class text by using beautifulsoup
I try我试试
for html in soup.find_all('div', {'class': 'sg-row'}):
name = html.find('span', {'class': 'a-size-medium a-colour-base a-text-normal'})
print(name)`
Output: i got text with whole html attributesVivo Y91i (Ocean Blue, 2Storage) required O/P i need only text :Vivo Y91i (Ocean Blue, 2GB RAM, 32GB Storage)输出:我得到了带有整个 html 属性的文本 Vivo Y91i(海洋蓝,2Storage)需要 O/P 我只需要文本:Vivo Y91i(海洋蓝,2GB RAM,32GB 存储)
Use .text
in order to print the text within the tag:使用
.text
来打印标签内的文本:
for html in soup.find_all('div', {'class': 'sg-row'}):
name = html.find('span', {'class': 'a-size-medium a-colour-base a-text-normal'})
print(name.text)
` import requests
from bs4 import BeautifulSoup
for html in soup.find_all('div', {'class': 'sg-row'}):
name = html.find('span', {'class': 'a-size-medium a-colour-base a-text-
normal'})
cleanr = re.compile('<.*?>')
product_name = re.sub(cleanr,str(name))
print(product_name)`
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.