Skip to content

Commit 8c4d27a

Browse files
black-tmin-oilcclauss
authored andcommitted
added daily horoscope scrapper script (TheAlgorithms#2167)
* added daily horoscope scrapper * Update daily horoscope scrapper script code refactoring, script editing * Update web_programming/daily_horoscope.py Co-authored-by: Christian Clauss <[email protected]>
1 parent 1b2af00 commit 8c4d27a

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

web_programming/daily_horoscope.py

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
from bs4 import BeautifulSoup
2+
import requests
3+
4+
5+
def horoscope(zodiac_sign: int, day: str) -> str:
6+
url = (
7+
"https://www.horoscope.com/us/horoscopes/general/"
8+
f"horoscope-general-daily-{day}.aspx?sign={zodiac_sign}"
9+
)
10+
soup = BeautifulSoup(requests.get(url).content, "html.parser")
11+
return soup.find("div", class_="main-horoscope").p.text
12+
13+
14+
if __name__ == "__main__":
15+
print("Daily Horoscope. \n")
16+
print(
17+
"enter your Zodiac sign number:\n",
18+
"1. Aries\n",
19+
"2. Taurus\n",
20+
"3. Gemini\n",
21+
"4. Cancer\n",
22+
"5. Leo\n",
23+
"6. Virgo\n",
24+
"7. Libra\n",
25+
"8. Scorpio\n",
26+
"9. Sagittarius\n",
27+
"10. Capricorn\n",
28+
"11. Aquarius\n",
29+
"12. Pisces\n",
30+
)
31+
zodiac_sign = int(input("number> ").strip())
32+
print("choose some day:\n", "yesterday\n", "today\n", "tomorrow\n")
33+
day = input("enter the day> ")
34+
horoscope_text = horoscope(zodiac_sign, day)
35+
print(horoscope_text)

0 commit comments

Comments
 (0)