基礎類封裝 瀏覽器檔案上載類庫封裝

2022-07-30 03:42:13 字數 4008 閱讀 6082

1

#!/usr/bin/env python32#

-*- coding: utf-8 -*-3#

@time : 2020/1/7 21:384#

@author : tang yiwei5#

@email : [email protected]#

@file : uploadfile.py7#

@software: pycharm89

10"""

11win32gui.findwindow(ipclassname,ipwindowsname)

12自頂層視窗開始尋找匹配條件的視窗,並返回這個視窗的控制代碼

13ipclassname:類名,在spy++裡能夠看到;ipwindowsname:視窗名,標題欄能夠看到

1415

win32gui.findwindowex(hwndparent=0,hwndchildafter=0,ipszclass=none,ipsxwindow=none)

16搜尋類名和窗體名匹配的窗體,並返回這個窗體的控制代碼,找不到就返回0

17hwndparent:若不為0,則搜尋控制代碼為hwndparent的子窗體

18hwndchildafter:若不為0,則按照z-index的順序從hwndchildafter後開始搜尋子窗體,否則從第乙個子窗體開始搜尋

19ipszclass:字元型,是窗體的類名,可以在spy++裡能夠看到

20ipsxwindow:字元型,是視窗名,標題欄能看到

2122

win32gui.sendmessage(hwnd,msg,wparam,iparam)

23hwnd:整形,接收訊息的窗體控制代碼

24msg:整形,要傳送的訊息,這些訊息都是windows預先設定好的

25wparam:整形,訊息的wparam引數

26iparam:整形,訊息的iparam引數

27"""

2829

30import

win32gui

31import

win32con

3233

34def upload_file_by_chrome(filepath,syslanguage="en"

):35

"""36

谷歌瀏覽器上傳檔案控制項

37:param filepath:上傳檔案的路徑

38:param syslanguage:作業系統當前的語言環境,預設為en

39:return:none

40"""

41if syslanguage == "ch"

:42 dialog = win32gui.findwindow ("

#32770

", "開啟"

)43elif syslanguage == "en"

:44 dialog = win32gui.findwindow("

#32770

", "

open")

45else:46

print("

不支援的語言!")

47print

(dialog)48#

找到視窗

49 comboxex32 = win32gui.findwindowex(dialog,0,"

comboboxex32

",none)

50print

(comboxex32)

51 combox = win32gui.findwindowex(comboxex32,0,"

combobox

",none)

52print

(combox)

53 edit = win32gui.findwindowex(combox,0,"

edit

",none)

54print

(edit)

55if syslanguage == "ch"

:56 button = win32gui.findwindowex(dialog, 0, "

button

", "

開啟(&o)")

57elif syslanguage == "en"

:58 button = win32gui.findwindowex(dialog, 0, "

button

", "

&open")

59win32gui.sendmessage(edit,win32con.wm_settext,none,filepath)

60 win32gui.sendmessage(dialog,win32con.wm_command,1,button) #

點選開啟按鈕

6162

def upload_file_by_firefox(filepath,syslanguage="ch"

):63

"""64

火狐瀏覽器上傳檔案控制項

65:param filepath:上傳檔案的路徑

66:param syslanguage:作業系統當前的語言環境,預設為en

67:return:none

68"""

69if syslanguage == "ch"

:70 dialog = win32gui.findwindow ("

#32770

", "

檔案上傳")

71elif syslanguage == "en"

:72 dialog = win32gui.findwindow("

#32770

", "

open")

73else:74

print("

不支援的語言!")

75print

(dialog)76#

找到視窗

77 comboxex32 = win32gui.findwindowex(dialog,0,"

comboboxex32

",none)

78print

(comboxex32)

79 combox = win32gui.findwindowex(comboxex32,0,"

combobox

",none)

80print

(combox)

81 edit = win32gui.findwindowex(combox,0,"

edit

",none)

82print

(edit)

83if syslanguage == "ch"

:84 button = win32gui.findwindowex(dialog, 0, "

button

", "

開啟(&o)")

85elif syslanguage == "en"

:86 button = win32gui.findwindowex(dialog, 0, "

button

", "

&open")

87win32gui.sendmessage(edit,win32con.wm_settext,none,filepath)

88 win32gui.sendmessage(dialog,win32con.wm_command,1,button) #

點選開啟按鈕

8990

if__name__ == '

__main__':

91#upload_file_by_chrome(r"c:\users\administrator\desktop\clips\a.mov")

92 upload_file_by_firefox(r"

c:\users\administrator\desktop\clips\a.mov

")

簡單封裝瀏覽器 cookie 工具類

目前主流瀏覽器一般都支援 cookie 以下對 cookie 的操作進行簡單封裝,以方便使用 import from assets scripts config config import from assets scripts tools cookies操作類 export default new...

獲取瀏覽器資訊的類

如果不需要querystring,截掉 當前訪問者是否為蜘蛛程式 注 可通過手動更改瀏覽器user agent設定或者url後附加isrobot 1引數來偽造當前請求為蜘蛛程式 public static bool isrobot return isrobot public static strin...

利用WebClient類向伺服器上載檔案

net sdk 上面的開啟檔案的類 private filestream openfile else return null private void button2 click object sender,system.eventargs e private void button1 click ...