【发布时间】:2021-06-06 15:57:55
【问题描述】:
HTML
<div class="QRiHXd">
"Some very secret link" <<< This is the content I want to print out / btw is a link
</div>
代码
import requests
import urllib
import bs4
url = 'https://www.reddit.com/' # There is actually another link
url_contents = urllib.request.urlopen(url).read()
soup = bs4.BeautifulSoup(url_contents, "html.parser")
div = soup.find('div', {'class_': 'QRiHXd'})
content = str(div)
print(content)
我需要打印类中的文本,但是当我尝试打印时它返回:“无”,我不知道为什么。
【问题讨论】:
标签: python html python-3.x beautifulsoup