python - BeautifulSoup 查找类返回无

标签 python selenium beautifulsoup

我正在使用BeautifulSoup和python编写代码来从网站上抓取信息,在我尝试按“类”类别获取特定内容后,它返回“[]”,这是否意味着“无” ?

这是否意味着它没有什么可抓取的?

以下是我的代码:

import requests
from bs4 import BeautifulSoup

page = requests.get('https://www.metservice.com/towns-cities/locations/auckland/7-days')
soup = BeautifulSoup(page.content, 'html.parser')
week = soup.find_all(class_='IconWithText-content')

print(week)

最佳答案

问题是当您尝试抓取时,页面内容未加载,

您可以将seleniumBeautifulSoup一起使用

示例

import time
from bs4 import BeautifulSoup
from selenium import webdriver

url = "https://www.metservice.com/towns-cities/locations/auckland/7-days"
browser = webdriver.Firefox()
browser.get(url)
time.sleep(5)
html = browser.page_source
soup = BeautifulSoup(html, 'html.parser')
week = soup.find_all(class_='IconWithText-content')
print(week)

关于python - BeautifulSoup 查找类返回无,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61313517/

相关文章:

python - AES 加密 Golang 和 Python

Python Selenium - 尝试按类名查找元素时出错

python - 在 Python 中使用变量的问题

python美汤提取数据

python - 如何使用 BeautifulSoup (python) 防止关闭错误 HTML 中的标签?

python - 使用 Python 代码清除控制台时如何修复 "TERM environment variable not set"?

python - 对 OpenCV FaceRecognizer 预测方法输出的信心

python - 这些替代的 numpy `uniform` 与 `random` 结构可能有何不同?

selenium - Protractor : ERROR - Unable to start a WebDriver session

javascript - 如何让 Protractor 不等待 $timeout?