从python中的html标签打印数字

时间:2018-07-13 18:32:00

标签: python beautifulsoup

嗨,我一直在尝试从以下网站获取时间数据:docs(小时,分钟,秒),并尝试使用beautifulsoup打印' span class =“ big '标签,因为时间信息保存在那里,我想出了这个:

from bs4 import BeautifulSoup
from requests import Session

session = Session()
session.headers['user-agent'] = (
    'Mozilla/5.0 (Windows NT 10.0; Win64; x64) '
    'AppleWebKit/537.36 (KHTML, like Gecko) Chrome/'
    '66.0.3359.181 Safari/537.36'
)

url = 'https://clockofeidolon.com'
response = session.get(url=url)

data = response.text
soup = BeautifulSoup(data, "html.parser")
spans = soup.find_all('<span class="big')

print([span.text for span in spans])

但是输出仅显示“ []”,而没有其他显示。我该如何打印三个标签中每个标签上的数字?

1 个答案:

答案 0 :(得分:1)

如上所述,一旦安装了正确的geckodriver,就可以使用硒实现以下目标:

from bs4 import BeautifulSoup
from selenium import webdriver

driver = webdriver.Firefox()
driver.get('https://clockofeidolon.com')
html = driver.page_source
soup = BeautifulSoup(html,'lxml')

spans = soup.find_all(class_='big-hour')
for span in spans:
        print(span.text)



driver.quit()