简体   繁体   English

我想要使​​用beautifulsoup跨类文本

[英]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)`

从中获取文本<div id="text_translate"><p>所以我试图从网站上获取特定的文本,但它只会给我错误 (floor = soup.find('span', {'class': 'text-white fs-14px text-truncate attribute-value'}) .text AttributeError: 'NoneType' object 没有属性 'text')</p><p> 我特别想获得“底价”文本。</p><p> 我的代码:</p><pre> import bs4 from bs4 import BeautifulSoup #target url url = "https://magiceden.io/marketplace/solsamo" #act like browser headers = {'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36'} response = requests.get('https://magiceden.io/marketplace/solsamo') #parse the downloaded page soup = BeautifulSoup(response.content, 'lxml') floor = soup.find('span', {'class': 'text-white fs-14px text-truncate attribute-value'}).text print(floor)</pre></div> - Get text from <span class: with Beautifulsoup and requests

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 BeautifulSoup: <div class <span class> <span class>我想要的文字</span> - BeautifulSoup: <div class <span class></span><span class>TEXT I WANT</span> 使用 BeautifulSoup 在没有类名的情况下提取跨度内的文本 - Extract text inside span without class name using BeautifulSoup 使用 BeautifulSoup 提取跨度文本 - Using BeautifulSoup to extract span text 如何使用beautifulsoup在嵌套跨度中抓取文本? - How do I scrape a text in nested span using beautifulsoup? 我无法使用 BeautifulSoup 访问跨度中的文本 - I can't access the text in the span using BeautifulSoup 从中获取文本<div id="text_translate"><p>所以我试图从网站上获取特定的文本,但它只会给我错误 (floor = soup.find('span', {'class': 'text-white fs-14px text-truncate attribute-value'}) .text AttributeError: 'NoneType' object 没有属性 'text')</p><p> 我特别想获得“底价”文本。</p><p> 我的代码:</p><pre> import bs4 from bs4 import BeautifulSoup #target url url = "https://magiceden.io/marketplace/solsamo" #act like browser headers = {'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36'} response = requests.get('https://magiceden.io/marketplace/solsamo') #parse the downloaded page soup = BeautifulSoup(response.content, 'lxml') floor = soup.find('span', {'class': 'text-white fs-14px text-truncate attribute-value'}).text print(floor)</pre></div> - Get text from <span class: with Beautifulsoup and requests 使用BeautifulSoup从span类中提取锚文本 - Extracting anchor text from span class with BeautifulSoup 如何在报废后删除跨度标签和类名,而我只想使用 python 爬取文本 - how to remove span tag and class name after scrapping whereas i want to scrape only text using python 我正在尝试使用 BeautifulSoup 获取产品信息,但无法获取之间的文本<span> </span> - i'm trying to get product information using BeautifulSoup, but unable to get the text between <span> </span> 如何从跨度标签和跨度 BeautifulSoup 中的 class 获取文本 - How to get text from span tag and span class in BeautifulSoup
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM