💻 源代码
import requests
from lxml import etree
def search_succulent(name):
"""查询多肉植物信息"""
url = f'https://www.baike.com/wiki/{name}'
headers = {'User-Agent': 'Mozilla/5.0'}
res = requests.get(url, headers=headers)
html = etree.HTML(res.text)
info = {
'name': html.xpath('//h1/text()'),
'alias': html.xpath('//div[@class="alias"]/text()'),
'description': html.xpath('//div[@class="summary"]/text()'),
'care': html.xpath('//div[@class="care"]/text()')
}
return info
def get_recommendation(season):
"""根据季节推荐多肉"""
recommendations = {
'spring': ['桃蛋', '熊童子', '虹之玉'],
'summer': ['法师', '山地玫瑰', '玉露'],
'autumn': ['乌木', '弗兰克', '橙梦露'],
'winter': ['长生草', '十二卷', '寿']
}
return recommendations.get(season, [])
# 示例
info = search_succulent('桃蛋')
print(f"名称: {info['name']}")
print(f"养护: {info['care']}")