標籤:
1、改改註冊表,使遊戲全屏:
import win32apiimport win32conChildKey = "SYSTEM\\ControlSet001\\Control\\GraphicsDrivers\\Configuration\\CMN14760_33_07DB_14^CD1210F191996046BD4FAF7270B5C9BB\\00\\00"handle = win32api.RegOpenKey(win32con.HKEY_LOCAL_MACHINE,ChildKey,0,win32con.KEY_ALL_ACCESS)getnum = win32api.RegQueryValueEx(handle,‘Scaling‘)win32api.RegSetValueEx(handle,‘Scaling‘,0,win32con.REG_DWORD,0x3)win32api.RegCloseKey(handle)
2、往圖片右上方添加數字,猶如qq訊息提示一樣:
from PIL import Imagefrom PIL import ImageFontfrom PIL import ImageDrawclass Draw: def __init__(self,name): self.name = name def open(self): try: self.pic = Image.open(self.name) except: print("檔案無法開啟") exit(1) def draw_pic(self,num): self.tar_size = max(self.pic.size[0],self.pic.size[1])/5 self.num = num self.tar_draw = str(self.num) if self.num < 100 else ‘99+‘ self.font = ImageFont.truetype("Arial.ttf",self.tar_size) self.px = self.pic.size[0] - self.font.getsize(self.tar_draw)[0] self.opened = ImageDraw.Draw(self.pic) self.opened.text((self.px,0),self.tar_draw,(255,0,0),self.font) self.pic.save("New.jpg") return Truefilename = raw_input("輸入檔案名稱:")obj = Draw(filename)obj.open()num = input(‘輸入數量:‘)obj.draw_pic(num)
3、爬蟲:
import urllib.requestimport osimport redef url_open(url): req = urllib.request.Request(url) req.add_header(‘User-Agent‘,‘Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40.0.2214.93 Safari/537.36‘) response = urllib.request.urlopen(url) html = response.read() return htmldef get_page(url): try: #print("正在嘗試utf-8解碼") html = url_open(url).decode("utf-8") except UnicodeDecodeError: #print("解碼失敗,嘗試GBK解碼") html = url_open(url).decode(‘GBK‘) rep = r‘forum\.php\?mod=viewthread&tid=([0-9]{5})‘ list1 = list(set(re.findall(rep,html))) #print(listone) print("函數get_page執行完畢。。。正在返回") return list1def page_open(list1): urlopen_page = ‘http://bbs.fishc.com/forum.php?mod=viewthread&tid=‘ os.mkdir(‘YuC‘) os.chdir(‘YuC‘) for each in list1: page_add = urlopen_page + each print("正在下載網址:" ,page_add) download_page(page_add)def download_page(page_add): get = url_open(page_add) filename = get_filename(get) #f1 = re.search(r‘id="thread_subject">(.*)</span>‘,get) #filename = str(f1[0]) print("建立檔案當中.........") with open(filename,‘wb‘) as f: f.write(get) print("檔案建立完畢!")def get_filename(get): try: #print("正在嘗試utf-8解碼") get = get.decode("utf-8") except UnicodeDecodeError: #print("解碼失敗,嘗試GBK解碼") get = get.decode(‘GBK‘) f1 = re.findall(r‘id="thread_subject">(.*)</span>‘,get) filename = str(f1[0]) +‘.html‘ return filenameif __name__ == ‘__main__‘: url = ‘http://bbs.fishc.com/forum.php?mod=forumdisplay&fid=255&typeid=420&typeid=420&filter=typeid&page=‘ for i in range(4): url = url + str(i) list1 = get_page(url) page_open(list1)
Python【Show Me The Code】小功能