我正试图从BBC最受欢迎的栏目中列出十大新闻文章。我的代码如下:
from bs4 import BeautifulSoup, SoupStrainer
import urllib2
import re
opener = urllib2.build_opener()
url = 'http://www.bbc.co.uk/news/popular/read'
soup = BeautifulSoup(opener.open(url), "lxml")
titleTag = soup.html.head.title
print(titleTag.string)
tagSpan = soup.find_all("span");
for tag in tagSpan:
print(tag.get("class"))
我要找的是<span class="most-popular-page-list-item__headline">
和</span>
之间的字符串
如何获取字符串并列出这些字符串的列表?你知道吗
这个怎么样:
相关问题 更多 >
编程相关推荐