一小伙使用 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
  • 基於.NET Framework 4.8 開發的深度學習模型部署測試平臺,提供了YOLO框架的主流系列模型,包括YOLOv8~v9,以及其系列下的Det、Seg、Pose、Obb、Cls等應用場景,同時支持圖像與視頻檢測。模型部署引擎使用的是OpenVINO™、TensorRT、ONNX runti... ...
  • 十年沉澱,重啟開發之路 十年前,我沉浸在開發的海洋中,每日與代碼為伍,與演算法共舞。那時的我,滿懷激情,對技術的追求近乎狂熱。然而,隨著歲月的流逝,生活的忙碌逐漸占據了我的大部分時間,讓我無暇顧及技術的沉澱與積累。 十年間,我經歷了職業生涯的起伏和變遷。從初出茅廬的菜鳥到逐漸嶄露頭角的開發者,我見證了 ...
  • C# 是一種簡單、現代、面向對象和類型安全的編程語言。.NET 是由 Microsoft 創建的開發平臺,平臺包含了語言規範、工具、運行,支持開發各種應用,如Web、移動、桌面等。.NET框架有多個實現,如.NET Framework、.NET Core(及後續的.NET 5+版本),以及社區版本M... ...
  • 前言 本文介紹瞭如何使用三菱提供的MX Component插件實現對三菱PLC軟元件數據的讀寫,記錄了使用電腦模擬,模擬PLC,直至完成測試的詳細流程,並重點介紹了在這個過程中的易錯點,供參考。 用到的軟體: 1. PLC開發編程環境GX Works2,GX Works2下載鏈接 https:// ...
  • 前言 整理這個官方翻譯的系列,原因是網上大部分的 tomcat 版本比較舊,此版本為 v11 最新的版本。 開源項目 從零手寫實現 tomcat minicat 別稱【嗅虎】心有猛虎,輕嗅薔薇。 系列文章 web server apache tomcat11-01-官方文檔入門介紹 web serv ...
  • 1、jQuery介紹 jQuery是什麼 jQuery是一個快速、簡潔的JavaScript框架,是繼Prototype之後又一個優秀的JavaScript代碼庫(或JavaScript框架)。jQuery設計的宗旨是“write Less,Do More”,即倡導寫更少的代碼,做更多的事情。它封裝 ...
  • 前言 之前的文章把js引擎(aardio封裝庫) 微軟開源的js引擎(ChakraCore))寫好了,這篇文章整點js代碼來測一下bug。測試網站:https://fanyi.youdao.com/index.html#/ 逆向思路 逆向思路可以看有道翻譯js逆向(MD5加密,AES加密)附完整源碼 ...
  • 引言 現代的操作系統(Windows,Linux,Mac OS)等都可以同時打開多個軟體(任務),這些軟體在我們的感知上是同時運行的,例如我們可以一邊瀏覽網頁,一邊聽音樂。而CPU執行代碼同一時間只能執行一條,但即使我們的電腦是單核CPU也可以同時運行多個任務,如下圖所示,這是因為我們的 CPU 的 ...
  • 掌握使用Python進行文本英文統計的基本方法,並瞭解如何進一步優化和擴展這些方法,以應對更複雜的文本分析任務。 ...
  • 背景 Redis多數據源常見的場景: 分區數據處理:當數據量增長時,單個Redis實例可能無法處理所有的數據。通過使用多個Redis數據源,可以將數據分區存儲在不同的實例中,使得數據處理更加高效。 多租戶應用程式:對於多租戶應用程式,每個租戶可以擁有自己的Redis數據源,以確保數據隔離和安全性。 ...