from collections import deque
import random

吳盈霖 發表在 痞客邦 留言(0) 人氣()


在工作排程器裡,工作的內容,其中動作視窗有三個參數需要設置。

第一個,是python執行檔所在的位置,以上圖為例,為 c:\program files\python35\python.exe

(前後有沒有雙引號是不影響執行結果的)

第二個,是python檔案所在的完整路徑,以上圖為例,為d:\python\helloworld.py

第三個,是python檔案所在的目錄,以上圖為例,為d:\python\



如果沒有設置第三個,那麼工作排程器會預設一開始的路徑為 c:\windows\system32\

也因此,python檔案若有要輸出檔案,若沒有指定絕對路徑,檔案會放在 c:\windows\system32\目錄下。

吳盈霖 發表在 痞客邦 留言(0) 人氣()

用記事本開啟matplotlibrc  我的路徑如下:C:\Anaconda3\Lib\site-packages\matplotlib\mpl-data\matplotlibrc

將下面三行前面的#取消
font.family : sans-serif   

font.serif : DejaVu Serif, Bitstream Vera Serif, ……

axes.unicode_minus : False ………

吳盈霖 發表在 痞客邦 留言(2) 人氣()

#載入pandas模組
import pandas as pd

吳盈霖 發表在 痞客邦 留言(0) 人氣()



#說明上圖中k值及d值是透過javascript採非同步傳輸方式,將資料載入至iframe框架中,若直接使用requests.get()的話,是拿不到裡面資料的。
# -*- coding: utf-8 -*-
import time,os
from selenium import webdriver #載入selenium模組
driver=webdriver.PhantomJS(r'c:\phantomjs.exe') #啟動web browser模擬器
driver.get("https://tw.screener.finance.yahoo.net/screener/check.html?symid=2029")
try:
    driver.switch_to_frame('screenercheck') #切換到frame框架中,括號中的內容是iframe's id
    a=driver.find_element_by_id('Kline')
    b=driver.find_element_by_id('Dline')
    print(a.text,b.text)
finally:
    driver.quit()
time.sleep(2)
 

吳盈霖 發表在 痞客邦 留言(0) 人氣()


   
wb=openpyxl.load_workbook('test.xlsx')
ws=wb.get_sheet_by_name('test')

吳盈霖 發表在 痞客邦 留言(0) 人氣()



方法一:
import openpyxl,os

吳盈霖 發表在 痞客邦 留言(0) 人氣()



import openpyxl,os
def inputData():
    dirpath=os.getcwd()+'/' #取得目前工作路徑
    filename='test.xlsx'
    fullpath=os.path.join(dirpath,filename) 
    wb=openpyxl.load_workbook(filename)
    ws=wb.get_sheet_by_name('test')  #取得工作表test
    data=['apple','orange','banana','gruva','grape']
    d=iter(data) #將串列資料置入迭代器中
    for row in ws['a1':'e1']:
        try:
            for cell in row:
                cell.value=next(d) #因為迭代器到末端之後再呼叫會出現錯誤,所以以try…except的方式來執行,忽略報錯
        except:
            pass

吳盈霖 發表在 痞客邦 留言(0) 人氣()

from win32com import client
import os
docApp=client.Dispatch('Word.Application')
cpath=os.path.dirname(__file__)
doc=docApp.Documents.Open(cpath+r"\doc\text.docx")  #與word應用程式連結,並產生word物件
range1=doc.Range(doc.Content.Start,doc.Content.End) #把原文件的內容傳給range1
range1.InsertAfter(",別懷疑,有很多人都是這麼相信的") #在range1變數的後面新增文字
doc.Content=range1  #把變數range1的內容指定給原文件
doc.Save()   #存檔
doc.Close()
docApp.Quit()

吳盈霖 發表在 痞客邦 留言(0) 人氣()

#---------------新增的個空的word 文件-------------------------------
import win32com,os #載入win32,os模組
from win32com.client import *

吳盈霖 發表在 痞客邦 留言(0) 人氣()


from bokeh.plotting import figure,show,output_file  
output_file('lineout.html')  #輸出成html檔,檔名為lineout.html
p=figure(width=800,height=400,title='零用金統計表')  #圖表尺寸大小為800×400
p.title.text_color='green'  #圖表標題顏色為綠色,字體大小為18
p.title.text_font_size='18pt'
p.xaxis.axis_label='年齡'  #x座標名稱
p.yaxis.axis_label='零用金'  #y座標名稱
listx1=[1,5,7,9,13,16]   #x座標資料
listy1=[15,30,50,60,80,90]   #y座標資料
dashs=[12,4]  #虛線顯示點數,第一個是顯示點數為12,而空白點數為4點
p.line(listx1,listy1,line_width=4,line_color='red',line_alpha=0.3,line_dash=dashs,legend='男性')  #legend是圖例所顯示的內容
listx2=[2,6,8,11,14,16]
listy2=[10,40,30,50,80,60]
p.line(listx2,listy2,line_width=4,line_color='blue',legend='女性')
show(p)

吳盈霖 發表在 痞客邦 留言(0) 人氣()


#查找49樂合彩本期號碼
import requests
from bs4 import BeautifulSoup as bs
url='http://www.taiwanlottery.com.tw/'
html=requests.get(url)  #取得樂透彩網站html內容
html.encoding='utf8'
sp=bs(html.text,'html.parser')  #使用beautifulsoup套件來解析網頁內容
data1=sp.select('table') #將所有的表格,取出,存成list
data2=data1[3].find_all('span')  #比對樂和彩表格是第幾個表格,並將表格內所有的<span>為開頭的全找出來
print("本期樂合彩開獎號碼".center(30))
print("="*40)
for i in range(3,9):
    print(data2[i].text.strip(),end='  ')  #列印內容
print()
for i in range(11,17):
    print(data2[i].text.strip(),end='  ')
print("開獎順序")
print("="*40)    

吳盈霖 發表在 痞客邦 留言(0) 人氣()

1 2 3 4
Blog Stats
⚠️

成人內容提醒

本部落格內容僅限年滿十八歲者瀏覽。
若您未滿十八歲,請立即離開。

已滿十八歲者,亦請勿將內容提供給未成年人士。