【发布时间】:2018-11-02 21:46:07
【问题描述】:
所以我试图只检索 p 标签中的信息,我不想要其他任何东西。我该怎么做?这就是我到目前为止所做的。我收到了我不需要的其他信息
page = requests.get('https://www.theguardian.com/world/2016/jun/30/mexican-
woman-117-years-old-dies-birth-certificate')
soup = BeautifulSoup(page.text, 'html.parser')
#soup.i.decompose()
content_list = soup.find('body')
# Pull text from all instances of <p> tag within BodyText div
content_list_items = content_list.find_all('p')
for content_list in content_list_items:
print(content_list.prettify())
【问题讨论】:
-
您的意思是删除
p中的所有标签,但保留所有文本?
标签: python python-3.x beautifulsoup