Python 在beautifulsoup中使用findAll筛选结果
问题似乎是,我想要的信息是在故事正文,但它是在最底部。所以我最终得到了大量的垃圾信息,直到我到达那里Python 在beautifulsoup中使用findAll筛选结果,python,search,beautifulsoup,findall,Python,Search,Beautifulsoup,Findall,问题似乎是,我想要的信息是在故事正文,但它是在最底部。所以我最终得到了大量的垃圾信息,直到我到达那里 import urllib2 from BeautifulSoup import BeautifulSoup result = urllib2.urlopen("http://www.bbc.co.uk/news/uk-scotland-south-scotland-12380537") html=result.read() soup= BeautifulSoup(html) print so
import urllib2
from BeautifulSoup import BeautifulSoup
result = urllib2.urlopen("http://www.bbc.co.uk/news/uk-scotland-south-scotland-12380537")
html=result.read()
soup= BeautifulSoup(html)
print soup.html.head.title
print soup.findAll('div', attrs={ "class" : "story-body"})
仅获取第一个
在本例中还有8个需要收集
所以希望从介绍开始到故事结尾都能收集到。。。有什么想法吗 就CSS选择器而言,您希望选择
.story body
中的所有p
元素:
print soup.findAll('p', attrs={ 'class' : "introduction"})
对于CSS选择器,您希望选择
中的所有p
元素。故事正文
:
print soup.findAll('p', attrs={ 'class' : "introduction"})
。你没有用漂亮的汤4,是吗?不,在这个例子中没有,我想我明天会继续,你应该这样做。对于新代码,没有什么理由不升级…您没有使用Beautiful Soup 4,是吗?在本例中没有,我想我明天会继续讨论,您应该这样做。对于新代码,没有什么理由不升级。