preface

I believe that in our daily life, when we get together, we always have a chat, especially girls like to talk about horoscopes. What horoscopes do the boys have? What horoscopes do the boys have? Today I will meet your need to know the arrangement of Heaven through the reptile:

1. Website analysis

The first step, how to open the web site: www.horoscope.com/us/index.as…

You can see this page

What we’re going to do today is we’re going to make a gadget that tells you what your horoscope is for three days,

There are twelve constellations, and I clicked on the first and second ones, Aries and Taurus:

You see a pattern

My ugly face broke into a big smile as I looked at the link.

In other words, www.horoscope.com/us/horoscop…

horoscope-general-daily-today.aspx? sign=1

Just change today and sign={} to get the url of each constellation

https://www.horoscope.com/us/horoscopes/general/horoscope-general-daily-today.aspx?sign=1
Copy the code

When we open yesterday’s horoscope for Taurus, we find that “daily” becomes “tomorrow”

We only get three days here, yesterday, today, tomorrow, and we just type in the console the date we want to query.

2. Get content

From the image we can get the content we need, this is very basic crawler, no reverse crawl, we directly into the code.

3. Code

from bs4 import BeautifulSoup import requests def horoscope(zodiac_sign: int, day: str) -> str: url = ( "https://www.horoscope.com/us/horoscopes/general/" f"horoscope-general-daily-{day}.aspx?sign={zodiac_sign}" Soup = BeautifulSoup(pleads.get (URL).content, "html.parser") return soup. Find ("div", Class_ ="main-horoscope").p.ext# Returns the obtained content -- instructions from heavenCopy the code

If you do not know your star sign, you need a function to query the star sign:

Def check_sign():# get constellation your_birth_day = input(" Enter your birthday date > ") your_birth_month = input(" Enter your birthday month > ") if (int(your_birth_month) == 12 and int(your_birth_day) >= 22) or ( int(your_birth_month) == 1 and int(your_birth_day) <= 19) : sign = "Capricorn" elif (int(your_birth_month) == 1 and int(your_birth_day) >= 20) or ( int(your_birth_month) == 2 and int(your_birth_day) <= 17 ): sign = "Aquarium" elif (int(your_birth_month) == 2 and int(your_birth_day) >= 18) or ( int(your_birth_month) == 3 and int(your_birth_day) <= 19 ): sign = "Pices" elif (int(your_birth_month) == 3 and int(your_birth_day) >= 20) or ( int(your_birth_month) == 4 and int(your_birth_day) <= 19 ): sign = "Aries" elif (int(your_birth_month) == 4 and int(your_birth_day) >= 20) or ( int(your_birth_month) == 5 and int(your_birth_day) <= 20 ): sign = "Taurus" elif (int(your_birth_month) == 5 and int(your_birth_day) >= 21) or ( int(your_birth_month) == 6 and int(your_birth_day) <= 20 ): sign = "Gemini" elif (int(your_birth_month) == 6 and int(your_birth_day) >= 21) or ( int(your_birth_month) == 7 and int(your_birth_day) <= 22 ): sign = "Cancer" elif (int(your_birth_month) == 7 and int(your_birth_day) >= 23) or ( int(your_birth_month) == 8 and int(your_birth_day) <= 22 ): sign = "Leo" elif (int(your_birth_month) == 8 and int(your_birth_day) >= 23) or ( int(your_birth_month) == 9 and int(your_birth_day) <= 22 ): sign = "Virgo" elif (int(your_birth_month) == 9 and int(your_birth_day) >= 23) or ( int(your_birth_month) == 10 and int(your_birth_day) <= 22 ): sign = "Libra" elif (int(your_birth_month) == 10 and int(your_birth_day) >= 23) or ( int(your_birth_month) == 11 and int(your_birth_day) <= 21 ): sign = "Scorpio" elif (int(your_birth_month) == 11 and int(your_birth_day) >= 22) or ( int(your_birth_month) == 12 and int(your_birth_day) <= 21 ): sign = "Sagittarius" return signCopy the code

4. In field

How’s that? Very interesting, of course, the website has a lot of use, and so on LATER I will continue to update, to achieve more fun features.

Recommend more courses:

Java Basics: Java300 set course -Java essential quality tutorial _ Hand by hand graphic learning Java, make learning to be a pleasure _

Python Basics: Getting started with Python! Crash Course Python for beginners! Two months can be the kind of post!

Java Game Project: [Java Project] Develop a full set of king of Glory tutorials and materials, make King of Glory in Java in less than 2 hours

Front End Foundation: Super dry! A week to build a Xiaomi mall! Web front-end zero basic entry HTML5+ CSS3, learn to build a website to see this is enough!