分類彙整:python

python selenium-1

https://www.youtube.com/watch?v=ff5L6L5MTCw 取得標籤範例: BY LINK drive.find_element(By.LINK_TEXT,"要搜尋文字") BY CLASS drive.find_element(By.CLASS_NAME,"要搜尋文字") 操作標籤: 取得標籤內部文字: element=drive.find_element(搜尋欄位,"要搜尋條件") element.text 取得標籤屬性: element=drive.find_element(搜尋欄位,"要搜尋條件") element.get_attribute("屬性名稱") 模擬click: element=drive.find_element(搜尋欄位,"要搜尋條件") element.click(). ===================== #爬ppt stock #pip install selenium #https://www.ptt.cc/bbs/Stock/index.html from selenium import webdriver from selenium.webdriver.common.by import By from selenium.webdriver.chrome.options import Options #chrom driver path … 繼續閱讀 →

發表於 python | 發表迴響

python

print %d 整數列印 %f float列印 %s string列印 %e 科學記號列印 %5d 固定列印 5位元 整數 ,少於5位元 左邊自動填入空白,大於5位元全部列印 %5s 固定列印 5位元 string ,少於5位元 左邊自動填入空白 ,大於5位元全部列印 %8.2f 固定列印 8位元 float 含小數點 %-8.2f 固定列印 8位元 float 含小數點 -右邊自動填入空白

發表於 python | 發表迴響

python exe

1.安裝 pip install pyinstaller 參數 pyinstaller -h #help -F #打包成EXE -icon #圖標 -w #視窗化 -c #console -D #創建目錄 ,含EXE 及依賴性文件 python -b test.py 可以使__pycache__ 資料夾不出現 # win10 64bit 下編譯無法在 win764bit 上使用,要64 +32 bit 可用需在 python32 下使用 https://medium.com/pyladies-taiwan/python-%E5%B0%87python%E6%89%93%E5%8C%85%E6%88%90exe%E6%AA%94-32a4bacbe351

發表於 python | 發表迴響

python 初學參考網站

https://steam.oxxostudio.tw/category/python/info/start.html?fbclid=IwAR1UQN1kaNIfIbKcMC2IOzsDT9CcpxodvlFeIFBiH_uDm9CV0vqKeDaMphI

發表於 python | 發表迴響

python function

字典 利用 get 取值 get(‘key’,’no data’) #1:key值, 2:none 後顯示 keys() #取得所有 key values() #取得所有 values items() #取得所有 key 和values 範例 dict2.itmes()

發表於 python | 發表迴響

python 確認檔案和目錄

# python os.path.isfile() os.path.isdir() os.path.exists() #https://shengyu7697.github.io/python-os-path-isdir/ #https://shengyu7697.github.io/python-os-path-isfile/ import os dir="ppp" print("—–確認目錄開始——") #print(os.path.isdir(dir)) print ("os.path.isdir(範例)") checkdir=os.path.isdir(dir) if checkdir: print("目錄存在") else: print("目錄不存在") print ("os.path.exists(範例)") checkdir=os.path.exists(dir) if checkdir: print("目錄存在") else: print("目錄不存在") #確認檔案開始 print("—–確認檔案開始——") print ("os.path.isfile(範例)") files="jjj.txt" checkfile=os.path.isfile(files) if checkfile: print("檔案存在") else: print("檔案不存在") print … 繼續閱讀 →

發表於 python | 發表迴響

python 安裝 pip.py

python 安裝時 勾選 add all users path path 記得選擇 c:\Python310\ 並加入 c:\Python310\ 和 c:\Python310\scripts 下載 https://bootstrap.pypa.io/get-pip.py python get-pip.py 參考: https://www.maxlist.xyz/2019/07/13/pip-install-python/

發表於 python | 發表迴響

python: json 檔案處理

#file.py import json as j with open("config.json", mode="r", encoding="utf-8″) as f: data=j.load(f) print(data) #data 是一個字典 print ("name" + " :", data["name"]) print ("version" + " :", data["version"]) #修改寫入 data["name"]="New Name" with open("config.json", mode="w", encoding="utf-8″)as f: j.dump(data, f) #在讀取 with open("config.json", … 繼續閱讀 →

發表於 python | 發表迴響

python: File 處理

#file.py with open("test.txt", mode="w", encoding="utf-8″) as file: file.write("測試中文") #如果檔案為utf8時,檔案第一列會有一個字元BOM,python encodeing=utf-8 列印時會有"\ufeff"輸出 # ,encoding 改為 utf-8-sig 讀取時會 去除 檔案抬頭 的 BOM with open("test.txt", mode="r", encoding="utf-8-sig") as file: data=file.read(2) print(data)

發表於 python | 發表迴響