小编Puj*_*apu的帖子

如何提取div标签中的强元素

我是网络抓取的新手。我正在使用 Python 来抓取数据。有人可以帮助我如何从以下位置提取数据:

<div class="dept"><strong>LENGTH:</strong> 15 credits</div>
Run Code Online (Sandbox Code Playgroud)

我的输出应该是长度: 15 credits

这是我的代码:

from urllib.request import urlopen
from bs4 import BeautifulSoup 

length=bsObj.findAll("strong")
for leng in length:
    print(leng.text,leng.next_sibling)
Run Code Online (Sandbox Code Playgroud)

输出:

DELIVERY:  Campus
LENGTH:  2 years
OFFERED BY:  Olin Business School
Run Code Online (Sandbox Code Playgroud)

但我只想有长度。

网站:http : //www.mastersindatascience.org/specialties/business-analytics/

python beautifulsoup web-scraping

4
推荐指数
1
解决办法
8721
查看次数

标签 统计

beautifulsoup ×1

python ×1

web-scraping ×1