-1
獲取段落標記的內容時有點困惑。獲取段落內容
<div class="SomeID">
<p>What a voice! </p>
</div>
我在這一點上
list = soup.find_all("div","SomeID")
可是如何才能讓該段內容達成。(什麼聲音!)
的基本問題是讓所有段落標記從內容
import urllib
from bs4 import BeautifulSoup
html = urllib.urlopen('http://www.dawn.com/news/1267272/democracys-woes').read()
soup = BeautifulSoup(html, 'html.parser')
list = soup.find_all("div","comment__body cf")
print list
兩者都不起作用。我正在更新這個問題。請粗略瀏覽一下。 –
@AliMurtaza好吧,'div.comment__body> p'適合我。 – alecxe
它不工作: 進口的urllib 從BS4進口BeautifulSoup HTML =了urllib.urlopen( 'http://www.dawn.com/news/1267272/democracys-woes').read() 湯= BeautifulSoup (html,'html.parser') #list = soup.find_all(「div」,「comment__body cf」) #print list list2 = soup.select_one(「div.comment__body cf> p」)。get_text strip = True) print list2 –