一小伙使用 python爬蟲來算命?

来源:https://www.cnblogs.com/liuliumei/archive/2022/09/26/16732820.html
-Advertisement-
Play Games

1.網站分析因版權原因,網站的地址大家可以私信我或者加我文章結尾的qq,完整的教程群里有,需要的自提,當然遇到問題也可以請教哦。 2.獲取內容我們今天呢,就先做一個通過星座來得知三天的運勢的小玩意, 這裡有十二個星座,我點了第一個和第二個進去,也就是白羊座和金牛座: 就會發現一個規律 通過觀察網址的 ...


1.網站分析
因版權原因,網站的地址大家可以私信我或者加我文章結尾的qq,完整的教程群里有,需要的自提,當然遇到問題也可以請教哦。

2.獲取內容
我們今天呢,就先做一個通過星座來得知三天的運勢的小玩意,

這裡有十二個星座,我點了第一個和第二個進去,也就是白羊座和金牛座:

就會發現一個規律
 

 

 

 

 

 

 

通過觀察網址的鏈接,我這張醜臉泛起了燦爛的笑容。

也就是說,https://www.horoscope.com/us/horoscopes/general/是每個星座都共有的一段網址,

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

我們只需改變today和sign={}對應的值就可以獲取到每個星座對應的網址了
 

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

我們再打開金牛座的昨天的運勢,發現daily-後面變成了tomorrow

 

3.代碼

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(requests.get(url).content, "html.parser")
    return soup.find("div", class_="main-horoscope").p.text#返回得到的內容——來自上天的指示

如果有小伙伴不知道自己的星座怎麼辦呢,所以我們就還需要一個函數去查詢星座:

def check_sign():#得到星座
    your_birth_day = input("輸入您的生日的日期> ")
    your_birth_month = input("輸入你生日的月份> ")
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"
PythonQUN:748,989,764 
 return sign


4.實操

 

 

 

 

 

怎麼樣?很有趣吧,當然網站有很多的用處,等以後我會繼續更新,實現更多的好玩的功能。


您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
  • 本章內容將從各個角度來對動畫整個體系進行分類,並且介紹各種前端動畫的實現方法,最後我們將總結在實際開發中的各個場景的動畫選擇方案 ...
  • ==面試題 ##1.vue2中的響應式原理簡述 響應式原理主要就是通過數據劫持,依賴收集,派發更新的方式來實現的 1.數據劫持,vue2是通過Object.defineProperty方法的get、set來將對對象進行遞歸劫持。 其中修改對象的屬性時 就會觸發set, 使用對象的屬性時就會觸發get ...
  • 原型模式 介紹 定義:用一個已經創建的實例作為原型,通過複製該原型對象來創建一個和原型對象相同的新對象。 簡單理解,就是當需要創建一個指定的對象時,我們剛好有一個這樣的對象,但是又不能直接使用,我會clone一個一模一樣的新對象來使用,這就是原型模式。關鍵字:Clone。 原型模式分為“深拷貝”和“ ...
  • 定義 **責任鏈模式(Chain of Responsibility Pattern)**中,有一條由請求處理者對象組成的鏈條,每個對象(除最後一個對象外)都持有下一個對象的引用,請求發送者將請求發送給第一個對象,請求就會順著鏈條走下去,直到有對象能夠處理請求。該模式將多個處理者對象解耦,使得請求發 ...
  • 本文主要從研發人員的角度,結合研發人員日常常見的各類業務場景,從經典系統框架的每一層入手分析冪等處理的時機。希望通過這篇文章的分析,讓開發者在日常開發中對冪等的處理不再陌生。抓住導致請求、介面不冪等的本質,在工作中避免再陷入這個陷阱中。 ...
  • 代理設計模式(Proxy Design Pattern)指的是,在不改變原始類(或叫被代理類)代碼的情況下,通過引入代理類來給原始類附加功能,即擴展目標對象的功能。 ...
  • 【1】為什麼要使用線程池? 示例演示: //設置業務模擬 class MyRunnable implements Runnable { private int count; public MyRunnable(int count) { this.count = count; } public int ...
  • 探索密碼學的奇妙之旅。介紹CTR、混合密碼系統、RSA-OAEP相關理論。並基於AES、RSA標準,使用golang crypto包實現了簡單混合加密系統。 ...
一周排行
    -Advertisement-
    Play Games
  • 前言 在我們開發過程中基本上不可或缺的用到一些敏感機密數據,比如SQL伺服器的連接串或者是OAuth2的Secret等,這些敏感數據在代碼中是不太安全的,我們不應該在源代碼中存儲密碼和其他的敏感數據,一種推薦的方式是通過Asp.Net Core的機密管理器。 機密管理器 在 ASP.NET Core ...
  • 新改進提供的Taurus Rpc 功能,可以簡化微服務間的調用,同時可以不用再手動輸出模塊名稱,或調用路徑,包括負載均衡,這一切,由框架實現並提供了。新的Taurus Rpc 功能,將使得服務間的調用,更加輕鬆、簡約、高效。 ...
  • 順序棧的介面程式 目錄順序棧的介面程式頭文件創建順序棧入棧出棧利用棧將10進位轉16進位數驗證 頭文件 #include <stdio.h> #include <stdbool.h> #include <stdlib.h> 創建順序棧 // 指的是順序棧中的元素的數據類型,用戶可以根據需要進行修改 ...
  • 前言 整理這個官方翻譯的系列,原因是網上大部分的 tomcat 版本比較舊,此版本為 v11 最新的版本。 開源項目 從零手寫實現 tomcat minicat 別稱【嗅虎】心有猛虎,輕嗅薔薇。 系列文章 web server apache tomcat11-01-官方文檔入門介紹 web serv ...
  • C總結與剖析:關鍵字篇 -- <<C語言深度解剖>> 目錄C總結與剖析:關鍵字篇 -- <<C語言深度解剖>>程式的本質:二進位文件變數1.變數:記憶體上的某個位置開闢的空間2.變數的初始化3.為什麼要有變數4.局部變數與全局變數5.變數的大小由類型決定6.任何一個變數,記憶體賦值都是從低地址開始往高地 ...
  • 如果讓你來做一個有狀態流式應用的故障恢復,你會如何來做呢? 單機和多機會遇到什麼不同的問題? Flink Checkpoint 是做什麼用的?原理是什麼? ...
  • C++ 多級繼承 多級繼承是一種面向對象編程(OOP)特性,允許一個類從多個基類繼承屬性和方法。它使代碼更易於組織和維護,並促進代碼重用。 多級繼承的語法 在 C++ 中,使用 : 符號來指定繼承關係。多級繼承的語法如下: class DerivedClass : public BaseClass1 ...
  • 前言 什麼是SpringCloud? Spring Cloud 是一系列框架的有序集合,它利用 Spring Boot 的開發便利性簡化了分散式系統的開發,比如服務註冊、服務發現、網關、路由、鏈路追蹤等。Spring Cloud 並不是重覆造輪子,而是將市面上開發得比較好的模塊集成進去,進行封裝,從 ...
  • class_template 類模板和函數模板的定義和使用類似,我們已經進行了介紹。有時,有兩個或多個類,其功能是相同的,僅僅是數據類型不同。類模板用於實現類所需數據的類型參數化 template<class NameType, class AgeType> class Person { publi ...
  • 目錄system v IPC簡介共用記憶體需要用到的函數介面shmget函數--獲取對象IDshmat函數--獲得映射空間shmctl函數--釋放資源共用記憶體實現思路註意 system v IPC簡介 消息隊列、共用記憶體和信號量統稱為system v IPC(進程間通信機制),V是羅馬數字5,是UNI ...