我正在使用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)
最佳答案
问题是当您尝试抓取时,页面内容未加载,
您可以将selenium
与BeautifulSoup
一起使用
示例
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/