【发布时间】:2020-03-21 23:21:42
【问题描述】:
我正在尝试在 Python 中使用 BeautifulSoup 来获取 CNN 中的搜索结果总数。
网页上的源代码是
<div class="cnn-search__results-count">
"Displaying results 1-10 out of 2208 for"
<strong>toronto</strong>
</div>
如截图1所示:
我写的代码是:
from bs4 import BeautifulSoup
import requests
url_cnn = 'https://www.cnn.com/search?q=toronto'
response_cnn = requests.get(url_cnn)
html_cnn = response_cnn.text
soup = BeautifulSoup(html_cnn, 'html.parser')
cnn = (soup.find('div', {"class": "cnn-search__results-count"}))
print(cnn)
但是,我只得到
<div class="cnn-search__results-count"></div>
中间的所有内容都不见了。
有谁知道如何解决这个问题?非常感谢!
【问题讨论】:
-
我建议添加与互联网和网站相关的标签。了解python和beautifulsoup可能还不够。
-
感谢永利夫!我添加了一些新标签
标签: python html web beautifulsoup web-crawler