發表文章

目前顯示的是有「python」標籤的文章

litv影片 公視+7 巴哈動畫瘋影片 下載教學

圖片
免責聲明 : 本教學僅僅是在教導如何使用 python   切勿使用在任何非法用途   網站僅供學習之用,使用者的行為一概與本站無關。請尊重版權。 先備條件 1.       下載 chromedriver ( https://chromedriver.storage.googleapis.com/index.html?path=2.30/ )        把下載的東西丟到C槽 2.       安裝 selenium (打開cmd 輸入 pip install selenium 或直接安裝 anaconda) 3.       找到 ts 檔的流水號連結網址 ( 應該都是這個 ) 步驟一、  先找到影片網址(按F12 --> Network-->將影片時間軸拉到最後-->找到影片流水號最後一碼-->按右鍵-->複製影片網址) 複製之後 打開Python   from selenium import webdriver # 利用瀏覽器下載,所以需要能驅動瀏覽器的模組 chrome_path = "C:\chromedriver.exe" #chromedriver.exe 執行檔所存在的路徑 web = webdriver.Chrome(chrome_path) # 驅動 chromedriver for i in range(283): # 括號內寫數字 = 要下載總數 +1     url =   " 網址 /media_ 流水號 "+str(i)+".ts"          web.get(url) 執行後就會開始下載,會新增一個瀏覽器視窗,然後下載那邊會一直新增 步驟二、第二個 python( 合併檔案...

python 生日日期星座查詢表

利用python達成 輸入月份日期 就可以該生日查詢對應的星座 同事在聊星座至少可以秒查= = 月 = int(input("請輸入月份")) 日 = int(input("請輸入日期")) def get_constellation(month, date):     dates = (21, 20, 21, 21, 22, 22, 23, 24, 24, 24, 23, 22)     constellations = ("摩羯座", "水瓶座", "雙魚座", "牡羊座", "金牛座", "雙子座", "巨蟹座", "獅子座", "處女座", "天秤座", "天蝎座", "射手座", "魔羯座")     if date < dates[month-1]:         return constellations[month-1]     else:         return constellations[month] print ((get_constellation(月,日)))

python爬蟲範例(以google新聞2019為例)

import requests from bs4 import BeautifulSoup res = requests.get("https://news.google.com/topics/CAAqKggKIiRDQkFTRlFvSUwyMHZNRGx1YlY4U0JYcG9MVlJYR2dKVVZ5Z0FQAQ?hl=zh-TW&gl=TW&ceid=TW%3Azh-Hant") #Google國際新聞的網址 soup = BeautifulSoup(res.text,"html.parser") for title,url in zip(soup.select("h4"),soup.select("h4 > a[href]")):     #Google有時會換字體大小 像是h3改成現在的h4     print ('')     print (title.text)     a = url['href'].replace("./", "")        print ('https://news.google.com/'+a)

python 如何把檔案轉成一行一行

先打開jupyter notebook 把檔案upload 檔名就是fname with open ( fname ) as f : content = f . readlines () #消掉換行、空白 content = [ x . strip () for x in content ]