Python 使用不带标签的 beautifulsoup 打印抓取的数据

标签 python python-2.7 beautifulsoup screen-scraping

<div class="number" title="Player number">1211</div>
<div class="shirt" title="sName">Ronaldo 1211</div>

我正在抓取一个网站。我已经成功打印出来了。这是我的代码:

web = urllib2.urlopen("WEBSITE")
soupit = BeautifulSoup(web, 'html.parser')
scrapeme = soupit.findAll("div", { "class" : "number" })
print scrapeme

打印出来:

<div class="id" title="Player number">1211</div>

我希望它只打印 1211。我该怎么做?

最佳答案

get_ text()任何 beautifulsoup 对象的方法都可以做到这一点。

print(scrapeme.get_text())

关于Python 使用不带标签的 beautifulsoup 打印抓取的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32428713/

相关文章:

python - 如何在python中返回一个空列表

python - 检查之后是否有 Tkinter 安排的方法

带参数的 Python 描述符?

python - 提取字母并填充单词的位置

python - 提取包含特定名称的列

Django - 检查模型是否有子级(相关模型)

python - pip install 给出错误 : Unable to find vcvarsall. bat

python - 使用beautifulsoup4根据 sibling 区分两个相同标签内容

xml - Python BeautifulSoup XML,AttributeError : can't set attribute, 如何设置为文本属性?

python - 简短而简单 - soup.find_all 不返回多个标签元素