问题是我不知道该怎么做。我正在尝试使用类 .first-text 打印
,它会打印整个 HTML。如何使用 BeatifulSoup 4 打印它?
import requests
from bs4 import BeautifulSoup
html = requests.get("http://lifehacker.com/this-video-explains-how-to-survive-a-free-falling-eleva-1738366697").text
soup = BeautifulSoup(html)
p = soup.p
meow = soup.find(p['class'] == "first-text")
if meow:
print(meow)
else:
print(404)
请您参考如下方法:
您正在解析 find 函数中的逻辑表达式,调用应该看起来像这样。
meow = soup.find('p', class="first-text")
通常您应该查看文档以获取此类信息,您会找到一组很好的示例和如何使用它的描述
