【发布时间】:2016-09-06 02:32:58
【问题描述】:
正如标题所示,我试图了解如何找到网站的第三个出现的<p>(例如,我使用了以下网站:http://www.musicmeter.nl/album/31759)。
使用this question的答案,我尝试了以下代码
from bs4 import BeautifulSoup
import requests
html = requests.get("http://www.musicmeter.nl/album/31759").text # get HTML from http://www.musicmeter.nl/album/31759
soup = BeautifulSoup(html, 'html5lib') # Get data out of HTML
first_paragraph = soup.find('p') # or just soup.p
print "first paragraph:", first_paragraph
second_paragraph = first_paragraph.find_next_siblings('p')
print "second paragraph:", second_paragraph
third_paragraph = second_paragraph.find_next_siblings('p')
print "third paragraph:", third_paragraph
但是这段代码导致第三段出现以下错误:
Traceback (most recent call last):
File "page_109.py", line 21, in <module>
third_paragraph = second_paragraph.find_next_siblings('p')
AttributeError: 'ResultSet' object has no attribute 'find_next_siblings'
我试图查找错误,但我无法找出问题所在。
【问题讨论】:
标签: python html beautifulsoup