以下是Python代码实现:

import requests
from bs4 import BeautifulSoup

# 获取汇率换算页面
url = 'https://hl.anseo.cn/'
response = requests.get(url)
soup = BeautifulSoup(response.text, 'html.parser')

# 找到汇率表格
table = soup.find('table', class_='table')
rows = table.find_all('tr')

# 遍历表格,获取每个国家的汇率
for row in rows[1:]:
    cells = row.find_all('td')
    country = cells[0].text.strip()
    rate = cells[1].text.strip()
    # 判断人民币兑英镑汇率是否小于7.6,加粗显示结果
    if country == '英镑' and float(rate) < 7.6:
        print(f"{country}: \033[1m{rate}\033[0m")
    else:
        print(f"{country}: {rate}")

运行结果示例:

美元: 6.4803
欧元: 7.7038
日元: 0.0589
港元: 0.8362
英镑: 8.9367
澳大利亚元: 4.9983
新西兰元: 4.6576
韩元: 0.0058
新加坡元: 4.8368
加拿大元: 5.1227

原文地址: http://www.cveoy.top/t/topic/mZ3 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录