TEXT I WANT 中获取文本-6ren"> TEXT I WANT 中获取文本-如何根据下面的屏幕截图获取总计 21,427 的文本。 我试过了,没用: rating_count = soup.find("span", attrs={'class':'rating_count'}-6ren">
gpt4 book ai didi

python - 如何在 Python 中从 TEXT I WANT 中获取文本

转载 作者:太空宇宙 更新时间:2023-11-03 13:14:29 24 4
gpt4 key购买 nike

如何根据下面的屏幕截图获取总计 21,427 的文本。

我试过了,没用:

rating_count = soup.find("span", attrs={'class':'rating_count'})
print rating_count

enter image description here

这是输出

enter image description here

最佳答案

这将完全满足您的需求。

from BeautifulSoup import BeautifulSoup

data='<span class="rating-count">TEXT I WANT</span>'
soup=BeautifulSoup(data)
t=soup.find('span',{'class':'rating-count'})
print t.text

编辑:

根据您提供的代码。看起来因为没有定义 header ,谷歌不会发送您要查找的信息。因此,BeautifulSoup 无法找到跨度,因为它实际上并不存在。试试这个,它对我有用:

pkg = "com.mavdev.focusoutfacebook"
url = "https://play.google.com/store/apps/details?id=" + pkg
opener = urllib2.build_opener()
opener.addheaders = [('User-agent', 'Mozilla/5.0')]
data = opener.open(url).read()

soup=BeautifulSoup(data)

t=soup.find('span',{'class':'rating-count'})
print t.text

结果:

>>> 
1,397

关于python - 如何在 Python 中从 <span class ="className">TEXT I WANT</span> 中获取文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34246574/

24 4 0