我需要使用beautifulsouppython从类标记中检索数据,而内部标记中没有数据

我需要使用beautifulsouppython从类标记中检索数据,而内部标记中没有数据,python,web-scraping,beautifulsoup,Python,Web Scraping,Beautifulsoup,我需要使用python库从“ikman.lk”中检索数据 <span class="t-small summary-count"> Showing 1-25 of 131 ads for <span>"Samsung Galaxy A5"</span>.</span> 但是它说“'NoneType'对象没有'text'属性”。 谢谢您需要找到

我需要使用python库从“ikman.lk”中检索数据

 <span class="t-small summary-count">  Showing 1-25 of 131 ads for <span>"Samsung Galaxy A5"</span>.</span>
但是它说“'NoneType'对象没有'text'属性”。 谢谢

您需要找到
选择
,然后使用
以前的同级

所有代码:

from bs4 import BeautifulSoup
html = ''' <span class="t-small summary-count">  Showing 1-25 of 131 ads for 
<span>"Samsung Galaxy A5"</span>.</span>
'''
soup = BeautifulSoup(html, 'lxml')
get_span = soup.find('span' , attrs={'class' : 't-small summary-count'})



for a in get_span.select('span'):
    print a.previousSibling
从bs4导入美化组
html=''显示131条广告中的1-25条
“三星Galaxy A5”。
'''
soup=BeautifulSoup(html,“lxml”)
get_span=soup.find('span',attrs={'class':'t-small summary count'})
对于in get_span.选择('span'):
打印a.previousSibling

如果我答对了问题,您需要在子标记之前从标记中获取初始文本。标记的子项在名为的列表中可用

您可以使用
.contents[0]

from bs4 import BeautifulSoup
html="""
<span class="t-small summary-count">  Showing 1-25 of 131 ads for <span>"Samsung Galaxy A5"</span>.</span>
"""
soup=BeautifulSoup(html,'html.parser')
pgn = soup.find("span", {"class": "t-small summary-count"})
print(pgn.contents)
print(pgn.contents[0])
从bs4导入美化组
html=”“”
显示“三星Galaxy A5”131个广告中的1-25个。
"""
soup=BeautifulSoup(html,'html.parser')
pgn=soup.find(“span”,“class”:“t-small汇总计数”})
打印(第页内容)
打印(pgn.contents[0])
输出

['  Showing 1-25 of 131 ads for ', <span>"Samsung Galaxy A5"</span>, '.']
  Showing 1-25 of 131 ads for 
[“显示”的131个广告中的1-25个,“三星Galaxy A5”和“.”
显示131条广告中的1-25条

您的确切问题是什么?我假设
find
不适用于多个类我只需要得到文本部分(“显示131个广告中的1-25个”)。如果你有办法的话,请帮忙。抱歉的伴侣可能会重复,这不是多节课的问题。在我的代码标签中只有一个类。但问题是我只需要提取文本部分。是否有办法仅检索第一个标记内的文本。是否确定“一个类”?在您的示例中,您已经给出了两个不同的类
t-small
summary count
——类名不能包含空格
['  Showing 1-25 of 131 ads for ', <span>"Samsung Galaxy A5"</span>, '.']
  Showing 1-25 of 131 ads for