【发布时间】:2019-08-01 13:35:00
【问题描述】:
我在使用 BeautifulSoup 时遇到了一些问题,使用 find_all() 方法。我正在尝试在所有 p 标签之间获取文本,但它只返回列表的第一个元素。实际上列表只有一项。为什么 find_all() 方法只返回一项?
这是我要提取的代码的一部分:
<div class="post-content">
<p>If you’re not familiar with Deep Image, it’s an amazing tool which allows you to increase the size of an image and upgrade its quality at the same time.</p>
<p>You can find it, and use for free <a href="https://deep-image.ai/">HERE</a></p>
<p><em>The goal of this blog post is to focus on the main changes and showcase the results of DI 2.0 algorithms.</em></p>
<p>As we all know a picture is worth a thousand words. So we will let the enhanced pictures speak for themselves. All pictures you can see below were processed using Deep Image algorithms.</p>
<h2 id="what-has-changed">What has changed</h2>
<p>Here are all the main improvements added to Deep Image 2.0:</p>
</div>
这是我的代码:
from bs4 import BeautifulSoup
import requests
source = requests.get('https://teonite.com/blog/deep-image-2-showcasing-results/').text
soup = BeautifulSoup(source, 'html.parser')
for article in soup.find_all(class_='post-content'):
print(article.p.text)
感谢您的帮助!
【问题讨论】:
-
样本输入只有一项具有所请求的类。
标签: python beautifulsoup