我用Python發(fā)現(xiàn)了 "十二星座" 中的秘密(附視頻)
1.寫(xiě)作靈感來(lái)源

2. 十二星座簡(jiǎn)介
3. 本文思路
① 定義一個(gè)函數(shù),輸入你的出生日期,獲取對(duì)應(yīng)的星座; ② 定義一個(gè)字典,根據(jù)不同的星座,得到星座對(duì)應(yīng)的英文,用于拼接url; ③ 獲取你的星座運(yùn)勢(shì);
1)定義一個(gè)函數(shù),輸入你的出生日期,獲取對(duì)應(yīng)的星座
def get_constellation(month, date):
dates = (21, 20, 21, 21, 22, 22, 23, 24, 24, 24, 23, 22)
constellations = ("摩羯座", "水瓶座", "雙魚(yú)座", "白羊座",
"金牛座", "雙子座", "巨蟹座", "獅子座",
"處女座", "天秤座", "天蝎座", "射手座", "摩羯座")
if date < dates[month-1]:
return constellations[month-1]
else:
return constellations[month]
constellation = get_constellation(7, 21)
print(f'根據(jù)你的出生日期,判斷你屬于"{constellation}"')

2)定義一個(gè)字典,根據(jù)不同的星座,得到星座對(duì)應(yīng)的英文,用于拼接url
dict_ = {"水瓶座":"Aquarius",
"雙魚(yú)座":"Pisces",
"白羊座":"Aries",
"金牛座":"Taurus",
"雙子座":"Gemini",
"巨蟹座":"Cancer",
"獅子座":"Leo",
"處女座":"Virgo",
"天秤座":"Libra",
"天蝎座":"Scorpio",
"射手座":"Sagittarius",
"摩羯座":"Capricorn"}
url = f"https://www.xzw.com/fortune/{dict_[constellation]}/"
url

3)獲取你的星座運(yùn)勢(shì)
lis = re.findall('<em style=" width:(.*?)px;">',content)
comprehensive_fortune,love_fortune,career_fortune,wealth_fortune = [str(int(int(i)/16))+"星" for i in lis]
health_index = re.findall('健康指數(shù):</label>(.*?)<',content,re.S)[0]
negotiation_Index = re.findall('商談指數(shù):</label>(.*?)<',content,re.S)[0]
lucky_color = re.findall('幸運(yùn)顏色:</label>(.*?)<',content,re.S)[0]
lucky_num = re.findall('幸運(yùn)數(shù)字:</label>(.*?)<',content,re.S)[0]
match_constellation = re.findall('速配星座:</label>(.*?)<',content,re.S)[0]
short_comment = re.findall('短評(píng):</label>(.*?)<',content,re.S)[0]

更多閱讀
特別推薦

點(diǎn)擊下方閱讀原文加入社區(qū)會(huì)員
評(píng)論
圖片
表情
