Web_Crawler.py 51 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963
  1. import Crawler_controller
  2. import os
  3. import tkinter
  4. from tkinter.filedialog import askdirectory
  5. import re
  6. import threading
  7. import time
  8. def Main():
  9. global top,Git,PATH,bg,bbg,fg,cookies_list,Attributes_Dict,DataBase_list
  10. DataBase_list = []
  11. Attributes_Dict = {}
  12. PATH = os.getcwd()
  13. top = tkinter.Tk()
  14. cookies_list = []
  15. bg = '#FFFAFA' # 主颜色
  16. bbg = '#FFFAFA' # 按钮颜色
  17. fg = '#000000' # 文字颜色
  18. top["bg"] = bg
  19. FONT = ('黑体', 11) # 设置字体
  20. top.title('CoTan自动化网页')
  21. top.resizable(width=False, height=False)
  22. top.geometry('+10+10') # 设置所在位置
  23. width_B = 13 # 标准宽度
  24. height_B = 2
  25. a_y = 0
  26. a_x = 0
  27. tkinter.Button(top, bg=bbg, fg=fg, text='添加url对象',command=add_url , font=FONT, width=width_B,
  28. height=height_B).grid(column=a_x, row=a_y, sticky=tkinter.E + tkinter.W)
  29. tkinter.Button(top, bg=bbg, fg=fg, text='删除url对象',command=del_url , font=FONT, width=width_B,
  30. height=height_B).grid(column=a_x+1, row=a_y, sticky=tkinter.E + tkinter.W)
  31. tkinter.Button(top, bg=bbg, fg=fg, text='应用过滤机制', font=FONT, width=width_B,
  32. height=height_B).grid(column=a_x+2, row=a_y, sticky=tkinter.E + tkinter.W)
  33. global URL_BOX,URL_Input,Func_BOX
  34. a_y += 1
  35. tkinter.Label(top, text='添加url:', bg=bg, fg=fg, font=FONT, width=width_B, height=height_B).grid(column=a_x,row=a_y)
  36. URL_Input = tkinter.Entry(top, width=width_B * 2)
  37. URL_Input.grid(column=a_x + 1, row=a_y, columnspan=2, sticky=tkinter.E + tkinter.W)
  38. global URL_ARGS,UA_Input,use_Cookies_Input,FUNC_Input,DATA_Input,TimeOut_Input
  39. a_y += 1
  40. URL_ARGS = []
  41. lable = ['不加载js','不加载java','不加载插件']#复选框
  42. for i in range(3):
  43. URL_ARGS.append(tkinter.IntVar())
  44. tkinter.Checkbutton(top,bg = bg,fg = fg,activebackground=bg,activeforeground=fg,selectcolor=bg, text=lable[i],
  45. variable=URL_ARGS[-1]).grid(column=a_x+i, row=a_y, sticky=tkinter.W)
  46. a_y += 1
  47. lable = ['第一次启动','隐藏网页','不加载图片']#复选框
  48. for i in range(3):
  49. URL_ARGS.append(tkinter.IntVar())
  50. tkinter.Checkbutton(top,bg = bg,fg = fg,activebackground=bg,activeforeground=fg,selectcolor=bg, text=lable[i],
  51. variable=URL_ARGS[-1]).grid(column=a_x+i, row=a_y, sticky=tkinter.W)
  52. a_y += 1
  53. tkinter.Label(top, text='UA设置:', bg=bg, fg=fg, font=FONT, width=width_B, height=height_B).grid(column=a_x,row=a_y)
  54. UA_Input = tkinter.Entry(top, width=width_B * 2)
  55. UA_Input.grid(column=a_x + 1, row=a_y, columnspan=2, sticky=tkinter.E + tkinter.W)
  56. a_y += 1
  57. tkinter.Label(top, text='DATA:', bg=bg, fg=fg, font=FONT, width=width_B, height=height_B).grid(column=a_x,row=a_y)
  58. DATA_Input = tkinter.Entry(top, width=width_B * 2)
  59. DATA_Input.grid(column=a_x + 1, row=a_y, columnspan=2, sticky=tkinter.E + tkinter.W)
  60. a_y += 1
  61. tkinter.Label(top, text='请求方式:', bg=bg, fg=fg, font=FONT, width=width_B, height=height_B).grid(column=a_x,row=a_y)
  62. FUNC_Input = tkinter.Entry(top, width=width_B * 2)
  63. FUNC_Input.grid(column=a_x + 1, row=a_y, columnspan=2, sticky=tkinter.E + tkinter.W)
  64. a_y += 1
  65. tkinter.Label(top, text='请求超时:', bg=bg, fg=fg, font=FONT, width=width_B, height=height_B).grid(column=a_x,row=a_y)
  66. TimeOut_Input = tkinter.Entry(top, width=width_B * 2)
  67. TimeOut_Input.grid(column=a_x + 1, row=a_y, columnspan=2, sticky=tkinter.E + tkinter.W)
  68. a_y += 1
  69. tkinter.Label(top, text='Cookies:', bg=bg, fg=fg, font=FONT, width=width_B, height=height_B).grid(column=a_x,row=a_y)
  70. use_Cookies_Input = tkinter.Entry(top, width=width_B)
  71. use_Cookies_Input.grid(column=a_x + 1, row=a_y, sticky=tkinter.E + tkinter.W)
  72. URL_ARGS.append(tkinter.IntVar())
  73. tkinter.Checkbutton(top, bg=bg, fg=fg, activebackground=bg, activeforeground=fg, selectcolor=bg, text='新启动网页',
  74. variable=URL_ARGS[-1]).grid(column=a_x + 2, row=a_y, sticky=tkinter.W)
  75. a_y += 1
  76. URL_BOX = tkinter.Listbox(top, width=width_B * 3, height=height_B * 4)
  77. URL_BOX.grid(column=a_x, row=a_y, columnspan=3, rowspan=4, sticky=tkinter.E + tkinter.W + tkinter.S + tkinter.N)
  78. a_y += 4
  79. tkinter.Button(top, bg=bbg, fg=fg, text='HTTPS过滤器',command=add_filter_func_HTTPS, font=FONT, width=width_B,height=height_B).grid(
  80. column=a_x, row=a_y, sticky=tkinter.E + tkinter.W)
  81. tkinter.Button(top, bg=bbg, fg=fg, text='WWW过滤器',command=add_filter_func_WWW, font=FONT, width=width_B,height=height_B).grid(
  82. column=a_x+1, row=a_y, sticky=tkinter.E + tkinter.W)
  83. tkinter.Button(top, bg=bbg, fg=fg, text='删除过滤器',command=del_func, font=FONT, width=width_B,height=height_B).grid(
  84. column=a_x+2, row=a_y, sticky=tkinter.E + tkinter.W)
  85. a_y += 1
  86. tkinter.Button(top, bg=bbg, fg=fg, text='自定义过滤器',command=add_filter_func_HTTPS, font=FONT, width=width_B,height=height_B).grid(
  87. column=a_x, row=a_y,columnspan=2, sticky=tkinter.E + tkinter.W)
  88. tkinter.Button(top, bg=bbg, fg=fg, text='清空过滤器', font=FONT, width=width_B,height=height_B).grid(
  89. column=a_x+2, row=a_y, sticky=tkinter.E + tkinter.W)
  90. global Func_BOX,cookies_fixed
  91. a_y += 1
  92. Func_BOX = tkinter.Listbox(top, width=width_B * 3, height=height_B * 3)
  93. Func_BOX.grid(column=a_x, row=a_y, columnspan=3, rowspan=3, sticky=tkinter.E + tkinter.W + tkinter.S + tkinter.N)
  94. global wait_Func_BOX,Wait_Input,cookies_BOX
  95. a_y += 3
  96. tkinter.Button(top, bg=bbg, fg=fg, text='单点爬虫运行',command=startDownloader, font=FONT, width=width_B,height=height_B).grid(
  97. column=a_x, row=a_y, sticky=tkinter.E + tkinter.W)
  98. tkinter.Button(top, bg=bbg, fg=fg, text='爬虫运行',command=Crawler_Run, font=FONT, width=width_B,height=height_B).grid(
  99. column=a_x+1, row=a_y, sticky=tkinter.E + tkinter.W)
  100. tkinter.Button(top, bg=bbg, fg=fg, text='单点爬虫停止',command=Crawler_Stop, font=FONT, width=width_B,height=height_B).grid(
  101. column=a_x+2, row=a_y, sticky=tkinter.E + tkinter.W)
  102. a_y += 1
  103. cookies_fixed = tkinter.Variable()
  104. tkinter.Label(top, text='【曲奇监视】', bg=bg, fg=fg, font=FONT, width=width_B, height=height_B).grid(
  105. column=a_x+1,row=a_y,sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N) # 设置说明
  106. tkinter.Checkbutton(top, bg=bg, fg=fg, activebackground=bg, activeforeground=fg, selectcolor=bg, text='固定曲奇',
  107. variable=cookies_fixed).grid(column=a_x + 2, row=a_y, sticky=tkinter.W)
  108. cookies_fixed.set('0')
  109. a_y += 1
  110. cookies_BOX = tkinter.Listbox(top, width=width_B * 3, height=height_B * 3)
  111. cookies_BOX.grid(column=a_x, row=a_y, columnspan=3, rowspan=3, sticky=tkinter.E + tkinter.W + tkinter.S + tkinter.N)
  112. a_y += 3
  113. tkinter.Button(top, bg=bbg, fg=fg, text='清空曲奇',command=Tra_cookies, font=FONT, width=width_B,height=height_B).grid(
  114. column=a_x, row=a_y, sticky=tkinter.E + tkinter.W)
  115. tkinter.Button(top, bg=bbg, fg=fg, text='更新曲奇',command=Update_cookies, font=FONT, width=width_B,height=height_B).grid(
  116. column=a_x+1, row=a_y, sticky=tkinter.E + tkinter.W)
  117. tkinter.Button(top, bg=bbg, fg=fg, text='删除曲奇',command=Del_cookies, font=FONT, width=width_B,height=height_B).grid(
  118. column=a_x+2, row=a_y, sticky=tkinter.E + tkinter.W)
  119. global cookies_Input,PAGE_BOX
  120. a_y += 1
  121. cookies_Input = tkinter.Entry(top, width=width_B * 3)
  122. cookies_Input.grid(column=a_x, row=a_y, columnspan=3, sticky=tkinter.E + tkinter.W)
  123. tkinter.Button(top, bg=bbg, fg=fg, text='添加曲奇',command=Add_cookies, font=FONT, width=width_B,height=height_B).grid(
  124. column=a_x+2, row=a_y, sticky=tkinter.E + tkinter.W)
  125. a_x += 3
  126. tkinter.Label(top, text='', bg=bg, fg=fg, font=FONT, width=1).grid(column=a_x, row=a_y) # 设置说明
  127. a_x += 1
  128. a_y = 0
  129. tkinter.Button(top, bg=bbg, fg=fg, text='根据id搜查',command=lambda :Page_Parser_addFindFunc('id'), font=FONT, width=width_B,height=height_B).grid(
  130. column=a_x, row=a_y, sticky=tkinter.E + tkinter.W)
  131. tkinter.Button(top, bg=bbg, fg=fg, text='根据name搜查',command=lambda :Page_Parser_addFindFunc('name'), font=FONT, width=width_B,height=height_B).grid(
  132. column=a_x+1, row=a_y, sticky=tkinter.E + tkinter.W)
  133. tkinter.Button(top, bg=bbg, fg=fg, text='根据class搜查',command=lambda :Page_Parser_addFindFunc('class'), font=FONT, width=width_B,height=height_B).grid(
  134. column=a_x+2, row=a_y, sticky=tkinter.E + tkinter.W)
  135. a_y += 1
  136. tkinter.Button(top, bg=bbg, fg=fg, text='根据xpath搜查',command=lambda :Page_Parser_addFindFunc('xpath'), font=FONT, width=width_B,height=height_B).grid(
  137. column=a_x, row=a_y, sticky=tkinter.E + tkinter.W)
  138. tkinter.Button(top, bg=bbg, fg=fg, text='根据css搜查',command=lambda :Page_Parser_addFindFunc('css'), font=FONT, width=width_B,height=height_B).grid(
  139. column=a_x+1, row=a_y, sticky=tkinter.E + tkinter.W)
  140. tkinter.Button(top, bg=bbg, fg=fg, text='根据元素名搜查',command=lambda :Page_Parser_addFindFunc('tag'), font=FONT, width=width_B,height=height_B).grid(
  141. column=a_x+2, row=a_y, sticky=tkinter.E + tkinter.W)
  142. global search_all,search_Input,Parser_Func_BOX
  143. a_y += 1
  144. search_all = tkinter.Variable()
  145. tkinter.Button(top, bg=bbg, fg=fg, text='根据link搜查',command=lambda :Page_Parser_addFindFunc('link'), font=FONT, width=width_B,height=height_B).grid(
  146. column=a_x, row=a_y, sticky=tkinter.E + tkinter.W)
  147. tkinter.Button(top, bg=bbg, fg=fg, text='link模糊搜查',command=lambda :Page_Parser_addFindFunc('partial_link'), font=FONT, width=width_B,height=height_B).grid(
  148. column=a_x+1, row=a_y, sticky=tkinter.E + tkinter.W)
  149. tkinter.Checkbutton(top, bg=bg, fg=fg, activebackground=bg, activeforeground=fg, selectcolor=bg, text='匹配全部',
  150. variable=search_all).grid(column=a_x + 2, row=a_y, sticky=tkinter.W)
  151. search_all.set('0')
  152. a_y += 1
  153. tkinter.Label(top, text='搜查参数:', bg=bg, fg=fg, font=FONT, width=width_B, height=height_B).grid(column=a_x,row=a_y)
  154. search_Input = tkinter.Entry(top, width=width_B * 2)
  155. search_Input.grid(column=a_x + 1, row=a_y, columnspan=2, sticky=tkinter.E + tkinter.W)
  156. a_y += 1
  157. tkinter.Button(top, bg=bbg, fg=fg, text='删除方法',command=Del_Parser_Func, font=FONT, width=width_B,height=height_B).grid(
  158. column=a_x, row=a_y,columnspan=2 , sticky=tkinter.E + tkinter.W)
  159. tkinter.Button(top, bg=bbg, fg=fg, text='清空方法',command=Tra_Parser_Func, font=FONT, width=width_B,height=height_B).grid(
  160. column=a_x+2, row=a_y, sticky=tkinter.E + tkinter.W)
  161. a_y += 1
  162. Parser_Func_BOX = tkinter.Listbox(top, width=width_B * 3, height=height_B * 5)
  163. Parser_Func_BOX.grid(column=a_x, row=a_y, columnspan=3, rowspan=5, sticky=tkinter.E + tkinter.W + tkinter.S + tkinter.N)
  164. global Var_Input,VarIndex_Input,Send_Input,UserPW_Input,SELE_Input,JS_Input,Time_Input
  165. a_y += 5
  166. tkinter.Label(top, text='操作元素:', bg=bg, fg=fg, font=FONT, width=width_B, height=height_B).grid(column=a_x,row=a_y)
  167. Var_Input = tkinter.Entry(top, width=width_B * 2)
  168. Var_Input.grid(column=a_x + 1, row=a_y, columnspan=2, sticky=tkinter.E + tkinter.W)
  169. a_y += 1
  170. tkinter.Label(top, text='操作索引:', bg=bg, fg=fg, font=FONT, width=width_B, height=height_B).grid(column=a_x,row=a_y)
  171. VarIndex_Input = tkinter.Entry(top, width=width_B * 2)
  172. VarIndex_Input.grid(column=a_x + 1, row=a_y, columnspan=2, sticky=tkinter.E + tkinter.W)
  173. a_y += 1
  174. tkinter.Label(top, text='发送信息:', bg=bg, fg=fg, font=FONT, width=width_B, height=height_B).grid(column=a_x,row=a_y)
  175. Send_Input = tkinter.Entry(top, width=width_B * 2)
  176. Send_Input.grid(column=a_x + 1, row=a_y, columnspan=2, sticky=tkinter.E + tkinter.W)
  177. a_y += 1
  178. tkinter.Label(top, text='认证用户名:', bg=bg, fg=fg, font=FONT, width=width_B, height=height_B).grid(column=a_x,row=a_y)
  179. UserName_Input = tkinter.Entry(top, width=width_B * 2)
  180. UserName_Input.grid(column=a_x + 1, row=a_y, columnspan=2, sticky=tkinter.E + tkinter.W)
  181. a_y += 1
  182. tkinter.Label(top, text='认证密码:', bg=bg, fg=fg, font=FONT, width=width_B, height=height_B).grid(column=a_x,row=a_y)
  183. UserPW_Input = tkinter.Entry(top, width=width_B * 2)
  184. UserPW_Input.grid(column=a_x + 1, row=a_y, columnspan=2, sticky=tkinter.E + tkinter.W)
  185. a_y += 1
  186. tkinter.Label(top, text='选择参数:', bg=bg, fg=fg, font=FONT, width=width_B, height=height_B).grid(column=a_x,row=a_y)
  187. SELE_Input = tkinter.Entry(top, width=width_B * 2)
  188. SELE_Input.grid(column=a_x + 1, row=a_y, columnspan=2, sticky=tkinter.E + tkinter.W)
  189. a_y += 1
  190. tkinter.Label(top, text='等待时间:', bg=bg, fg=fg, font=FONT, width=width_B, height=height_B).grid(column=a_x,row=a_y)
  191. Time_Input = tkinter.Entry(top, width=width_B * 2)
  192. Time_Input.grid(column=a_x + 1, row=a_y, columnspan=2, sticky=tkinter.E + tkinter.W)
  193. a_y += 1
  194. tkinter.Label(top, text='JavaScript:', bg=bg, fg=fg, font=FONT, width=width_B, height=height_B).grid(column=a_x,row=a_y)
  195. JS_Input = tkinter.Entry(top, width=width_B * 2)
  196. JS_Input.grid(column=a_x + 1, row=a_y, columnspan=2, sticky=tkinter.E + tkinter.W)
  197. a_y += 1
  198. tkinter.Button(top, bg=bbg, fg=fg, text='发送字符',command=lambda :Page_Parser_addActionFunc('send_keys'), font=FONT, width=width_B,height=height_B).grid(
  199. column=a_x, row=a_y, sticky=tkinter.E + tkinter.W)
  200. tkinter.Button(top, bg=bbg, fg=fg, text='清空字符',command=lambda :Page_Parser_addActionFunc('clear'), font=FONT, width=width_B,height=height_B).grid(
  201. column=a_x+1, row=a_y, sticky=tkinter.E + tkinter.W)
  202. tkinter.Button(top, bg=bbg, fg=fg, text='提交表单',command=lambda :Page_Parser_addActionFunc('submit'), font=FONT, width=width_B,height=height_B).grid(
  203. column=a_x+2, row=a_y, sticky=tkinter.E + tkinter.W)
  204. a_y += 1
  205. tkinter.Button(top, bg=bbg, fg=fg, text='点击按钮',command=lambda :Page_Parser_addActionFunc('click'), font=FONT, width=width_B,height=height_B).grid(
  206. column=a_x, row=a_y, sticky=tkinter.E + tkinter.W)
  207. tkinter.Button(top, bg=bbg, fg=fg, text='取得源代码',command=lambda :Page_Parser_addActionFunc('get_Page'), font=FONT, width=width_B,height=height_B).grid(
  208. column=a_x+1, row=a_y, sticky=tkinter.E + tkinter.W)
  209. tkinter.Button(top, bg=bbg, fg=fg, text='输出HTML',command=lambda :Page_Parser_addActionFunc('out'), font=FONT, width=width_B,height=height_B).grid(
  210. column=a_x+2, row=a_y, sticky=tkinter.E + tkinter.W)
  211. a_y += 1
  212. tkinter.Button(top, bg=bbg, fg=fg, text='切换Frame(id)',command=Page_Parser_addFrameFunc_id, font=FONT, width=width_B,height=height_B).grid(
  213. column=a_x, row=a_y, sticky=tkinter.E + tkinter.W)
  214. tkinter.Button(top, bg=bbg, fg=fg, text='切换Frame',command=lambda :Page_Parser_addFindFunc('frame'), font=FONT, width=width_B,height=height_B).grid(
  215. column=a_x+1, row=a_y, sticky=tkinter.E + tkinter.W)
  216. tkinter.Button(top, bg=bbg, fg=fg, text='定位焦点元素',command=lambda :Page_Parser_addFindFunc('active_element'), font=FONT, width=width_B,height=height_B).grid(
  217. column=a_x+2, row=a_y, sticky=tkinter.E + tkinter.W)
  218. a_y += 1
  219. tkinter.Button(top, bg=bbg, fg=fg, text='捕获弹窗',command=lambda :Page_Parser_addFindFunc('alert'), font=FONT, width=width_B,height=height_B).grid(
  220. column=a_x, row=a_y, sticky=tkinter.E + tkinter.W)
  221. tkinter.Button(top, bg=bbg, fg=fg, text='回到主Frame',command=lambda :Page_Parser_addFrameFunc_FP(False), font=FONT, width=width_B,height=height_B).grid(
  222. column=a_x+1, row=a_y, sticky=tkinter.E + tkinter.W)
  223. tkinter.Button(top, bg=bbg, fg=fg, text='回到父Frame',command=lambda :Page_Parser_addFrameFunc_FP(True), font=FONT, width=width_B,height=height_B).grid(
  224. column=a_x+2, row=a_y, sticky=tkinter.E + tkinter.W)
  225. a_y += 1
  226. tkinter.Button(top, bg=bbg, fg=fg, text='弹出框认证',command=lambda :Page_Parser_addActionFunc('User_Passwd'), font=FONT, width=width_B,height=height_B).grid(
  227. column=a_x, row=a_y, sticky=tkinter.E + tkinter.W)
  228. tkinter.Button(top, bg=bbg, fg=fg, text='弹出框确定',command=lambda :Page_Parser_addActionFunc('accept'), font=FONT, width=width_B,height=height_B).grid(
  229. column=a_x+1, row=a_y, sticky=tkinter.E + tkinter.W)
  230. tkinter.Button(top, bg=bbg, fg=fg, text='弹出框取消',command=lambda :Page_Parser_addActionFunc('dismiss'), font=FONT, width=width_B,height=height_B).grid(
  231. column=a_x+2, row=a_y, sticky=tkinter.E + tkinter.W)
  232. a_y += 1
  233. tkinter.Button(top, bg=bbg, fg=fg, text='取消选择index',command=lambda :Page_Parser_addActionFunc('deselect_by_index'), font=FONT, width=width_B,height=height_B).grid(
  234. column=a_x, row=a_y, sticky=tkinter.E + tkinter.W)
  235. tkinter.Button(top, bg=bbg, fg=fg, text='取消选择text',command=lambda :Page_Parser_addActionFunc('deselect_by_text'), font=FONT, width=width_B,height=height_B).grid(
  236. column=a_x+1, row=a_y, sticky=tkinter.E + tkinter.W)
  237. tkinter.Button(top, bg=bbg, fg=fg, text='取消选择value',command=lambda :Page_Parser_addActionFunc('deselect_by_value'), font=FONT, width=width_B,height=height_B).grid(
  238. column=a_x+2, row=a_y, sticky=tkinter.E + tkinter.W)
  239. a_y += 1
  240. tkinter.Button(top, bg=bbg, fg=fg, text='选择index',command=lambda :Page_Parser_addActionFunc('select_by_index'), font=FONT, width=width_B,height=height_B).grid(
  241. column=a_x, row=a_y, sticky=tkinter.E + tkinter.W)
  242. tkinter.Button(top, bg=bbg, fg=fg, text='选择text',command=lambda :Page_Parser_addActionFunc('select_by_text'), font=FONT, width=width_B,height=height_B).grid(
  243. column=a_x+1, row=a_y, sticky=tkinter.E + tkinter.W)
  244. tkinter.Button(top, bg=bbg, fg=fg, text='选择value',command=lambda :Page_Parser_addActionFunc('select_by_value'), font=FONT, width=width_B,height=height_B).grid(
  245. column=a_x+2, row=a_y, sticky=tkinter.E + tkinter.W)
  246. a_x += 3
  247. tkinter.Label(top, text='', bg=bg, fg=fg, font=FONT, width=1).grid(column=a_x, row=a_y) # 设置说明
  248. a_x += 1
  249. a_y = 0
  250. global Func_Output,Status_Output,FuncValue_BOX
  251. Func_Output = tkinter.StringVar()
  252. Status_Output = tkinter.StringVar()
  253. tkinter.Label(top, text='正在执行:', bg=bg, fg=fg, font=FONT, width=width_B, height=height_B).grid(column=a_x,row=a_y)
  254. tkinter.Entry(top, width=width_B * 2, state=tkinter.DISABLED,textvariable=Func_Output).grid(
  255. column=a_x + 1, row=a_y, columnspan=2, sticky=tkinter.E + tkinter.W)
  256. a_y += 1
  257. tkinter.Label(top, text='上一次状态:', bg=bg, fg=fg, font=FONT, width=width_B, height=height_B).grid(column=a_x,row=a_y)
  258. tkinter.Entry(top, width=width_B * 2, state=tkinter.DISABLED,textvariable=Status_Output).grid(
  259. column=a_x + 1, row=a_y, columnspan=2, sticky=tkinter.E + tkinter.W)
  260. a_y += 1
  261. FuncValue_BOX = tkinter.Listbox(top, width=width_B * 3, height=height_B * 5)
  262. FuncValue_BOX.grid(column=a_x, row=a_y, columnspan=3, rowspan=5, sticky=tkinter.E + tkinter.W + tkinter.S + tkinter.N)
  263. global CookiesName_Input,Cookies_Input,Tag_Input,AttributesName_Input,AttributesValue_Input
  264. global FindAllText_Input,text_re,attribute_re,limit_Input,recursive_Input,FindAllPATH_Input,Attributes_BOX
  265. a_y += 5
  266. tkinter.Label(top, text='cookies名:', bg=bg, fg=fg, font=FONT, width=width_B, height=height_B).grid(column=a_x,row=a_y)
  267. CookiesName_Input = tkinter.Entry(top, width=width_B * 2)
  268. CookiesName_Input.grid(column=a_x + 1, row=a_y, columnspan=2, sticky=tkinter.E + tkinter.W)
  269. a_y += 1
  270. tkinter.Label(top, text='cookies:', bg=bg, fg=fg, font=FONT, width=width_B, height=height_B).grid(column=a_x,row=a_y)
  271. Cookies_Input = tkinter.Entry(top, width=width_B * 2)
  272. Cookies_Input.grid(column=a_x + 1, row=a_y, columnspan=2, sticky=tkinter.E + tkinter.W)
  273. a_y += 1
  274. tkinter.Label(top, text='定位标签:', bg=bg, fg=fg, font=FONT, width=width_B, height=height_B).grid(column=a_x,
  275. row=a_y)
  276. Tag_Input = tkinter.Entry(top, width=width_B * 2)
  277. Tag_Input.grid(column=a_x + 1, row=a_y, columnspan=2, sticky=tkinter.E + tkinter.W)
  278. a_y += 1
  279. tkinter.Label(top, text='定位属性名:', bg=bg, fg=fg, font=FONT, width=width_B, height=height_B).grid(column=a_x,
  280. row=a_y)
  281. AttributesName_Input = tkinter.Entry(top, width=width_B * 2)
  282. AttributesName_Input.grid(column=a_x + 1, row=a_y, columnspan=2, sticky=tkinter.E + tkinter.W)
  283. attribute_re = tkinter.IntVar()
  284. a_y += 1
  285. tkinter.Label(top, text='定位属性值:', bg=bg, fg=fg, font=FONT, width=width_B, height=height_B).grid(column=a_x,
  286. row=a_y)
  287. AttributesValue_Input = tkinter.Entry(top, width=width_B)
  288. AttributesValue_Input.grid(column=a_x + 1,columnspan=2, row=a_y, sticky=tkinter.E + tkinter.W)
  289. a_y += 1
  290. tkinter.Button(top, bg=bbg, fg=fg, text='添加属性',command=add_Attributes, font=FONT, width=width_B,height=height_B).grid(
  291. column=a_x, row=a_y, sticky=tkinter.E + tkinter.W)
  292. tkinter.Button(top, bg=bbg, fg=fg, text='删除属性',command=del_Attributes, font=FONT, width=width_B,height=height_B).grid(
  293. column=a_x+1, row=a_y, sticky=tkinter.E + tkinter.W)
  294. tkinter.Button(top, bg=bbg, fg=fg, text='清空属性',command=tra_Attributes, font=FONT, width=width_B,height=height_B).grid(
  295. column=a_x+2, row=a_y, sticky=tkinter.E + tkinter.W)
  296. a_y += 1
  297. Attributes_BOX = tkinter.Listbox(top, width=width_B * 3, height=height_B * 3)
  298. Attributes_BOX.grid(column=a_x, row=a_y, columnspan=3, rowspan=3, sticky=tkinter.E + tkinter.W + tkinter.S + tkinter.N)
  299. a_y += 3
  300. tkinter.Label(top, text='定位文本:', bg=bg, fg=fg, font=FONT, width=width_B, height=height_B).grid(column=a_x,
  301. row=a_y)
  302. FindAllText_Input = tkinter.Entry(top, width=width_B)
  303. FindAllText_Input.grid(column=a_x + 1,columnspan=2, row=a_y, sticky=tkinter.E + tkinter.W)
  304. recursive_Input = tkinter.IntVar()
  305. text_re = tkinter.IntVar()
  306. a_y += 1
  307. tkinter.Checkbutton(top, bg=bg, fg=fg, activebackground=bg, activeforeground=fg, selectcolor=bg, text='递归查找',
  308. variable=recursive_Input).grid(column=a_x, row=a_y, sticky=tkinter.W)
  309. tkinter.Checkbutton(top, bg=bg, fg=fg, activebackground=bg, activeforeground=fg, selectcolor=bg, text='文本使用正则',
  310. variable=text_re).grid(column=a_x + 1, row=a_y, sticky=tkinter.W)
  311. tkinter.Checkbutton(top, bg=bg, fg=fg, activebackground=bg, activeforeground=fg, selectcolor=bg, text='属性值使用正则',
  312. variable=attribute_re).grid(column=a_x + 2, row=a_y, sticky=tkinter.W)
  313. attribute_re.set(1)
  314. text_re.set('1')
  315. recursive_Input.set('1')
  316. a_y += 1
  317. tkinter.Label(top, text='查找个数:', bg=bg, fg=fg, font=FONT, width=width_B, height=height_B).grid(column=a_x,
  318. row=a_y)
  319. limit_Input = tkinter.Entry(top, width=width_B * 2)
  320. limit_Input.grid(column=a_x + 1, row=a_y, columnspan=2, sticky=tkinter.E + tkinter.W)
  321. a_y += 1
  322. tkinter.Label(top, text='定位路径:', bg=bg, fg=fg, font=FONT, width=width_B, height=height_B).grid(column=a_x,
  323. row=a_y)
  324. FindAllPATH_Input = tkinter.Entry(top, width=width_B * 2)
  325. FindAllPATH_Input.grid(column=a_x + 1, row=a_y, columnspan=2, sticky=tkinter.E + tkinter.W)
  326. a_y += 1
  327. tkinter.Button(top, bg=bbg, fg=fg, text='删除所有曲奇',command=lambda :Page_Parser_addActionFunc2('del_all_cookies'), font=FONT, width=width_B,height=height_B).grid(
  328. column=a_x, row=a_y, sticky=tkinter.E + tkinter.W)
  329. tkinter.Button(top, bg=bbg, fg=fg, text='删除指定曲奇',command=lambda :Page_Parser_addActionFunc2('del_cookies'), font=FONT, width=width_B,height=height_B).grid(
  330. column=a_x+1, row=a_y, sticky=tkinter.E + tkinter.W)
  331. tkinter.Button(top, bg=bbg, fg=fg, text='添加新的曲奇',command=lambda :Page_Parser_addActionFunc2('add_cookies'), font=FONT, width=width_B,height=height_B).grid(
  332. column=a_x+2, row=a_y, sticky=tkinter.E + tkinter.W)
  333. a_y += 1
  334. tkinter.Button(top, bg=bbg, fg=fg, text='更新指定曲奇',command=lambda :Page_Parser_addActionFunc2('update_cookies'), font=FONT, width=width_B,height=height_B).grid(
  335. column=a_x, row=a_y, sticky=tkinter.E + tkinter.W)
  336. tkinter.Button(top, bg=bbg, fg=fg, text='获得所有曲奇',command=lambda :Page_Parser_addActionFunc2('get_cookies'), font=FONT, width=width_B,height=height_B).grid(
  337. column=a_x+1, row=a_y, sticky=tkinter.E + tkinter.W)
  338. tkinter.Button(top, bg=bbg, fg=fg, text='获得指定曲奇',command=lambda :Page_Parser_addActionFunc2('get_all_cookies'), font=FONT, width=width_B,height=height_B).grid(
  339. column=a_x+2, row=a_y, sticky=tkinter.E + tkinter.W)
  340. a_y += 1
  341. tkinter.Button(top, bg=bbg, fg=fg, text='解析网页',command=lambda :Page_Parser_addActionFunc2('make_bs'), font=FONT, width=width_B,height=height_B).grid(
  342. column=a_x, row=a_y, sticky=tkinter.E + tkinter.W)
  343. tkinter.Button(top, bg=bbg, fg=fg, text='根据标签定位',command=lambda :Page_Parser_addActionFunc2('findAll'), font=FONT, width=width_B,height=height_B).grid(
  344. column=a_x+1, row=a_y, sticky=tkinter.E + tkinter.W)
  345. tkinter.Button(top, bg=bbg, fg=fg, text='根据文本定位',command=lambda :Page_Parser_addActionFunc2('findAll_by_text'), font=FONT, width=width_B,height=height_B).grid(
  346. column=a_x+2, row=a_y, sticky=tkinter.E + tkinter.W)
  347. a_y += 1
  348. tkinter.Button(top, bg=bbg, fg=fg, text='获得子标签',command=lambda :Page_Parser_addActionFunc2('get_children'), font=FONT, width=width_B,height=height_B).grid(
  349. column=a_x, row=a_y, sticky=tkinter.E + tkinter.W)
  350. tkinter.Button(top, bg=bbg, fg=fg, text='获得后代标签',command=lambda :Page_Parser_addActionFunc2('get_offspring'), font=FONT, width=width_B,height=height_B).grid(
  351. column=a_x+1, row=a_y, sticky=tkinter.E + tkinter.W)
  352. tkinter.Button(top, bg=bbg, fg=fg, text='获得弟标签',command=lambda :Page_Parser_addActionFunc2('get_down'), font=FONT, width=width_B,height=height_B).grid(
  353. column=a_x+2, row=a_y, sticky=tkinter.E + tkinter.W)
  354. a_y += 1
  355. tkinter.Button(top, bg=bbg, fg=fg, text='获得兄标签',command=lambda :Page_Parser_addActionFunc2('get_up'), font=FONT, width=width_B,height=height_B).grid(
  356. column=a_x, row=a_y, sticky=tkinter.E + tkinter.W)
  357. tkinter.Button(top, bg=bbg, fg=fg, text='获得兄弟标签',command=lambda :Page_Parser_addActionFunc2('brothers'), font=FONT, width=width_B,height=height_B).grid(
  358. column=a_x+1, row=a_y, sticky=tkinter.E + tkinter.W)
  359. tkinter.Button(top, bg=bbg, fg=fg, text='路径定位',command=lambda :Page_Parser_addActionFunc2('get_by_path'), font=FONT, width=width_B,height=height_B).grid(
  360. column=a_x+2, row=a_y, sticky=tkinter.E + tkinter.W)
  361. a_x += 3
  362. tkinter.Label(top, text='', bg=bg, fg=fg, font=FONT, width=1).grid(column=a_x, row=a_y) # 设置说明
  363. a_x += 1
  364. a_y = 0
  365. tkinter.Label(top, text='【数据库操作】', bg=bg, fg=fg, font=FONT).grid(column=a_x, row=a_y,columnspan=3) # 设置说明
  366. a_y += 1
  367. tkinter.Button(top, bg=bbg, fg=fg, text='元素式存入',command=lambda :to_Database(True), font=FONT, width=width_B,height=height_B).grid(
  368. column=a_x, row=a_y, sticky=tkinter.E + tkinter.W)
  369. tkinter.Button(top, bg=bbg, fg=fg, text='正则式存入',command=lambda :to_Database(False), font=FONT, width=width_B,height=height_B).grid(
  370. column=a_x+1, row=a_y, sticky=tkinter.E + tkinter.W)
  371. tkinter.Button(top, bg=bbg, fg=fg, text='新增数据表',command=add_DataBase, font=FONT, width=width_B,height=height_B).grid(
  372. column=a_x+2, row=a_y, sticky=tkinter.E + tkinter.W)
  373. a_y += 1
  374. tkinter.Button(top, bg=bbg, fg=fg, text='删除数据表',command=remove_DataBase, font=FONT, width=width_B,height=height_B).grid(
  375. column=a_x, row=a_y, sticky=tkinter.E + tkinter.W)
  376. tkinter.Button(top, bg=bbg, fg=fg, text='导出数据表',command=out, font=FONT, width=width_B,height=height_B).grid(
  377. column=a_x+1, row=a_y, sticky=tkinter.E + tkinter.W)
  378. tkinter.Button(top, bg=bbg, fg=fg, text='关闭数据表', command=close, font=FONT,
  379. width=width_B, height=height_B).grid(column=a_x + 2, row=a_y, sticky=tkinter.E + tkinter.W)
  380. global Data_Input,DataBase_BOX,DataName_Input,URLTAG_Input
  381. a_y += 1
  382. tkinter.Label(top, text='数据存入格式:', bg=bg, fg=fg, font=FONT, width=width_B, height=height_B).grid(column=a_x,row=a_y)
  383. Data_Input = tkinter.Entry(top, width=width_B * 2)
  384. Data_Input.grid(column=a_x + 1, row=a_y, columnspan=2, sticky=tkinter.E + tkinter.W)
  385. a_y += 1
  386. tkinter.Label(top, text='数据表名字:', bg=bg, fg=fg, font=FONT, width=width_B, height=height_B).grid(column=a_x,row=a_y)
  387. DataName_Input = tkinter.Entry(top, width=width_B * 2)
  388. DataName_Input.grid(column=a_x + 1, row=a_y, columnspan=2, sticky=tkinter.E + tkinter.W)
  389. a_y += 1
  390. DataBase_BOX = tkinter.Listbox(top, width=width_B * 3, height=height_B * 5)
  391. DataBase_BOX.grid(column=a_x, row=a_y, columnspan=3, rowspan=5, sticky=tkinter.E + tkinter.W + tkinter.S + tkinter.N)
  392. a_y += 5
  393. tkinter.Label(top, text='URL标签:', bg=bg, fg=fg, font=FONT, width=width_B, height=height_B).grid(column=a_x,row=a_y)
  394. URLTAG_Input = tkinter.Entry(top, width=width_B * 2)
  395. URLTAG_Input.grid(column=a_x + 1, row=a_y, columnspan=2, sticky=tkinter.E + tkinter.W)
  396. a_y += 1
  397. tkinter.Button(top, bg=bbg, fg=fg, text='导出页面快照',command=lambda :Page_Parser_addActionFunc2('png'), font=FONT, width=width_B,height=height_B).grid(
  398. column=a_x, row=a_y, sticky=tkinter.E + tkinter.W)
  399. tkinter.Button(top, bg=bbg, fg=fg, text='回调添加URL',command=add_url_from_tag, font=FONT, width=width_B,height=height_B).grid(
  400. column=a_x+1, row=a_y, sticky=tkinter.E + tkinter.W)
  401. tkinter.Button(top, bg=bbg, fg=fg, text='解析为json', command=lambda :Page_Parser_addActionFunc2('to_json'), font=FONT,
  402. width=width_B, height=height_B).grid(column=a_x + 2, row=a_y, sticky=tkinter.E + tkinter.W)
  403. global Special_keys,Chains_Input,element_value2_Input,index2_Input,run_time,key_Input
  404. a_y += 1
  405. tkinter.Label(top, text='操作动作链:', bg=bg, fg=fg, font=FONT, width=width_B, height=height_B).grid(column=a_x,row=a_y)
  406. Chains_Input = tkinter.Entry(top, width=width_B * 2)
  407. Chains_Input.grid(column=a_x + 1, row=a_y, columnspan=2, sticky=tkinter.E + tkinter.W)
  408. a_y += 1
  409. tkinter.Label(top, text='拽拖至元素:', bg=bg, fg=fg, font=FONT, width=width_B, height=height_B).grid(column=a_x,row=a_y)
  410. element_value2_Input = tkinter.Entry(top, width=width_B * 2)
  411. element_value2_Input.grid(column=a_x + 1, row=a_y, columnspan=2, sticky=tkinter.E + tkinter.W)
  412. a_y += 1
  413. tkinter.Label(top, text='拽拖索引:', bg=bg, fg=fg, font=FONT, width=width_B, height=height_B).grid(column=a_x,row=a_y)
  414. index2_Input = tkinter.Entry(top, width=width_B * 2)
  415. index2_Input.grid(column=a_x + 1, row=a_y, columnspan=2, sticky=tkinter.E + tkinter.W)
  416. a_y += 1
  417. tkinter.Label(top, text='键入值:', bg=bg, fg=fg, font=FONT, width=width_B, height=height_B).grid(column=a_x,row=a_y)
  418. key_Input = tkinter.Entry(top, width=width_B * 2)
  419. key_Input.grid(column=a_x + 1, row=a_y, columnspan=2, sticky=tkinter.E + tkinter.W)
  420. a_y += 1
  421. tkinter.Label(top, text='运行时长:', bg=bg, fg=fg, font=FONT, width=width_B, height=height_B).grid(column=a_x,row=a_y)
  422. run_time = tkinter.Entry(top, width=width_B * 2)
  423. run_time.grid(column=a_x + 1, row=a_y, columnspan=2, sticky=tkinter.E + tkinter.W)
  424. a_y += 1
  425. tkinter.Button(top, bg=bbg, fg=fg, text='点击左键',command=lambda :Page_Parser_addActionFunc3('click'), font=FONT, width=width_B,height=height_B).grid(
  426. column=a_x, row=a_y, sticky=tkinter.E + tkinter.W)
  427. tkinter.Button(top, bg=bbg, fg=fg, text='双击左键',command=lambda :Page_Parser_addActionFunc3('double_click'), font=FONT, width=width_B,height=height_B).grid(
  428. column=a_x+1, row=a_y, sticky=tkinter.E + tkinter.W)
  429. tkinter.Button(top, bg=bbg, fg=fg, text='点击右键', command=lambda :Page_Parser_addActionFunc3('click_right'), font=FONT,
  430. width=width_B, height=height_B).grid(column=a_x + 2, row=a_y, sticky=tkinter.E + tkinter.W)
  431. a_y += 1
  432. tkinter.Button(top, bg=bbg, fg=fg, text='按住左键',command=lambda :Page_Parser_addActionFunc3('click_and_hold'), font=FONT, width=width_B,height=height_B).grid(
  433. column=a_x, row=a_y, sticky=tkinter.E + tkinter.W)
  434. tkinter.Button(top, bg=bbg, fg=fg, text='松开左键',command=lambda :Page_Parser_addActionFunc3('release'), font=FONT, width=width_B,height=height_B).grid(
  435. column=a_x+1, row=a_y, sticky=tkinter.E + tkinter.W)
  436. tkinter.Button(top, bg=bbg, fg=fg, text='拽托元素', command=lambda :Page_Parser_addActionFunc2('drag_and_drop'), font=FONT,
  437. width=width_B, height=height_B).grid(column=a_x + 2, row=a_y, sticky=tkinter.E + tkinter.W)
  438. a_y += 1
  439. tkinter.Button(top, bg=bbg, fg=fg, text='移动鼠标',command=lambda :Page_Parser_addActionFunc3('move'), font=FONT, width=width_B,height=height_B).grid(
  440. column=a_x, row=a_y, sticky=tkinter.E + tkinter.W)
  441. tkinter.Button(top, bg=bbg, fg=fg, text='按下按键',command=lambda :Page_Parser_addActionFunc3('key_down'), font=FONT, width=width_B,height=height_B).grid(
  442. column=a_x+1, row=a_y, sticky=tkinter.E + tkinter.W)
  443. tkinter.Button(top, bg=bbg, fg=fg, text='抬起按键', command=lambda :Page_Parser_addActionFunc3('key_up'), font=FONT,
  444. width=width_B, height=height_B).grid(column=a_x + 2, row=a_y, sticky=tkinter.E + tkinter.W)
  445. Special_keys = tkinter.IntVar()
  446. a_y += 1
  447. tkinter.Button(top, bg=bbg, fg=fg, text='发送文本到焦点',command=lambda :Page_Parser_addActionFunc3('send_keys'), font=FONT, width=width_B,height=height_B).grid(
  448. column=a_x, row=a_y, sticky=tkinter.E + tkinter.W)
  449. tkinter.Button(top, bg=bbg, fg=fg, text='发送文本',command=lambda :Page_Parser_addActionFunc3('send_keys_to_element'), font=FONT, width=width_B,height=height_B).grid(
  450. column=a_x+1, row=a_y, sticky=tkinter.E + tkinter.W)
  451. tkinter.Checkbutton(top, bg=bg, fg=fg, activebackground=bg, activeforeground=fg, selectcolor=bg, text='转换为特殊按钮',
  452. variable=Special_keys).grid(column=a_x + 2, row=a_y, sticky=tkinter.W)
  453. a_y += 1
  454. tkinter.Button(top, bg=bbg, fg=fg, text='生成动作链',command=lambda :Page_Parser_addActionFunc3('make_ActionChains'), font=FONT, width=width_B,height=height_B).grid(
  455. column=a_x, row=a_y, sticky=tkinter.E + tkinter.W)
  456. tkinter.Button(top, bg=bbg, fg=fg, text='运行动作链',command=lambda :Page_Parser_addActionFunc3('ActionChains_run'), font=FONT, width=width_B,height=height_B).grid(
  457. column=a_x+1,columnspan=2, row=a_y, sticky=tkinter.E + tkinter.W)
  458. a_y += 1
  459. tkinter.Button(top, bg=bbg, fg=fg, text='获取当前窗口',command=lambda :Page_Parser_addActionFunc('get_now_windows'), font=FONT, width=width_B,height=height_B).grid(
  460. column=a_x, row=a_y, sticky=tkinter.E + tkinter.W)
  461. tkinter.Button(top, bg=bbg, fg=fg, text='获取所有窗口',command=lambda :Page_Parser_addActionFunc('get_all_windows'), font=FONT, width=width_B,height=height_B).grid(
  462. column=a_x+1, row=a_y, sticky=tkinter.E + tkinter.W)
  463. tkinter.Button(top, bg=bbg, fg=fg, text='切换窗口', command=lambda :Page_Parser_addActionFunc('switch_to_windwos'), font=FONT,
  464. width=width_B, height=height_B).grid(column=a_x + 2, row=a_y, sticky=tkinter.E + tkinter.W)
  465. a_y += 1
  466. tkinter.Button(top, bg=bbg, fg=fg, text='暴力等待',command=lambda :Page_Parser_addActionFunc('wait_sleep'), font=FONT, width=width_B,height=height_B).grid(
  467. column=a_x, row=a_y, sticky=tkinter.E + tkinter.W)
  468. tkinter.Button(top, bg=bbg, fg=fg, text='元素检查等待',command=lambda :Page_Parser_addActionFunc('set_wait'), font=FONT, width=width_B,height=height_B).grid(
  469. column=a_x+1, row=a_y, sticky=tkinter.E + tkinter.W)
  470. tkinter.Button(top, bg=bbg, fg=fg, text='运行js',command=lambda :Page_Parser_addActionFunc('run_JS'), font=FONT, width=width_B,height=height_B).grid(
  471. column=a_x+2, row=a_y, sticky=tkinter.E + tkinter.W)
  472. a_y += 1
  473. tkinter.Button(top, bg=bbg, fg=fg, text='页面后退',command=lambda :Page_Parser_addActionFunc('back'), font=FONT, width=width_B,height=height_B).grid(
  474. column=a_x, row=a_y, sticky=tkinter.E + tkinter.W)
  475. tkinter.Button(top, bg=bbg, fg=fg, text='页面刷新',command=lambda :Page_Parser_addActionFunc('refresh'), font=FONT, width=width_B,height=height_B).grid(
  476. column=a_x+1, row=a_y, sticky=tkinter.E + tkinter.W)
  477. tkinter.Button(top, bg=bbg, fg=fg, text='页面前进',command=lambda :Page_Parser_addActionFunc('forward'), font=FONT, width=width_B,height=height_B).grid(
  478. column=a_x+2, row=a_y, sticky=tkinter.E + tkinter.W)
  479. top.update()#要预先update一下,否则会卡住
  480. global url,loader,Page_Parser,DataBase,save_dir
  481. save_dir = askdirectory(title='选择项目位置')#项目位置
  482. url = Crawler_controller.url(save_dir,save_dir)#url管理器
  483. loader = Crawler_controller.Page_Downloader(url,save_dir)#页面下载器
  484. Page_Parser = Crawler_controller.Page_Parser(loader)#页面解析器
  485. DataBase = Crawler_controller.data_base#数据库
  486. top.mainloop()
  487. #关闭操作
  488. loader.stop()
  489. DataBase.close_all()
  490. url.close()
  491. loader.close()
  492. def to_Database(is_tag=True):
  493. global VarIndex_Input,Var_Input,Data_Input,Page_Parser
  494. try:
  495. index = eval(VarIndex_Input.get(),{})
  496. except:
  497. index = slice(None,None)
  498. if is_tag:
  499. func = Page_Parser.to_Database
  500. else:
  501. func = Page_Parser.to_Database_by_re
  502. func(element_value=Var_Input.get(),index=index,data = Data_Input.get(),dataBase_name=get_DataBase_Name())
  503. Update_Parser_Func_BOX()
  504. def close():
  505. global DataBase
  506. name = get_DataBase_Name()
  507. DataBase.close(name)
  508. update_DataBase_BOX()
  509. def out():
  510. global save_dir,DataBase
  511. name = get_DataBase_Name()
  512. DataBase.out(name,save_dir)
  513. update_DataBase_BOX()
  514. def remove_DataBase():
  515. global DataBase
  516. name = get_DataBase_Name()
  517. DataBase.rm_dataBase(name)
  518. update_DataBase_BOX()
  519. def add_DataBase():
  520. global DataName_Input,DataBase
  521. name = DataName_Input.get()
  522. DataBase.add_DataBase(name)
  523. update_DataBase_BOX()
  524. def get_DataBase_Name():
  525. global DataBase_BOX,DataBase_list
  526. try:
  527. return DataBase_list[DataBase_BOX.curselection()[0]]
  528. except:
  529. try:
  530. return DataBase_list[0]
  531. except:
  532. return None
  533. def update_DataBase_BOX():
  534. global DataBase_BOX,DataBase_list
  535. DataBase_list = DataBase.return_database()
  536. DataBase_BOX.delete(0,tkinter.END)
  537. DataBase_BOX.insert(tkinter.END,*DataBase_list)
  538. def update_Status(now_func,status,Value_BOX):
  539. global Func_Output,Status_Output,FuncValue_BOX
  540. Func_Output.set(now_func)
  541. Status_Output.set(status)
  542. FuncValue_BOX.delete(0,tkinter.END)
  543. FuncValue_BOX.insert(0,*Value_BOX)
  544. def tra_Attributes():
  545. global Attributes_Dict
  546. Attributes_Dict = {}
  547. update_Attributes_BOX()
  548. def del_Attributes():
  549. global Attributes_BOX, Attributes_Dict
  550. del Attributes_Dict[list(Attributes_Dict.keys())[Attributes_BOX.curselection()[0]]]
  551. update_Attributes_BOX()
  552. def add_Attributes():
  553. global AttributesName_Input,AttributesValue_Input,attribute_re,Attributes_Dict
  554. name = AttributesName_Input.get()
  555. value = AttributesValue_Input.get()
  556. if name == '' or value == '': return False
  557. value = re.compile(value) if bool(attribute_re.get()) else value
  558. Attributes_Dict[name] = value
  559. update_Attributes_BOX()
  560. def update_Attributes_BOX():
  561. global Attributes_BOX,Attributes_Dict
  562. show = []
  563. for i in Attributes_Dict:
  564. show.append(f'{i} -> {Attributes_Dict[i]}')
  565. Attributes_BOX.delete(0, tkinter.END)
  566. Attributes_BOX.insert(tkinter.END,*show)
  567. def Func_Args3():#方法args统一转换(第三栏目)
  568. global Special_keys, Chains_Input, element_value2_Input, index2_Input, run_time,Var_Input,VarIndex_Input,key_Input
  569. try:
  570. index = int(VarIndex_Input.get())
  571. except:
  572. index = 0
  573. try:
  574. index2 = int(index2_Input.get())
  575. except:
  576. index2 = 0
  577. try:
  578. time = int(run_time.get())
  579. except:
  580. time = 1
  581. return dict(Chains=Chains_Input.get(),element_value=Var_Input.get(),index=index,element_value2=element_value2_Input.get(),
  582. index2=index2,run_time=time,is_special_keys = bool(Special_keys.get()),key=key_Input.get())
  583. def Func_Args2():#方法args统一转换(第二栏目)
  584. global CookiesName_Input,Cookies_Input,Tag_Input,Attributes_Dict,Var_Input,VarIndex_Input
  585. global FindAllText_Input,text_re,limit_Input,recursive_Input,FindAllPATH_Input
  586. try:
  587. index = eval(VarIndex_Input.get(),{})
  588. except:
  589. index = slice(None,None)
  590. try:
  591. cookies = eval(Cookies_Input.get(),{})
  592. except:
  593. cookies = {}
  594. return dict(element_value=Var_Input.get(),index=index,cookies_name=CookiesName_Input.get(),cookies=cookies,tag=Tag_Input.get().split(','),
  595. attribute=Attributes_Dict,text=re.compile(FindAllText_Input.get()) if bool(text_re.get()) else FindAllText_Input.get(),
  596. limit=limit_Input.get(),recursive=bool(recursive_Input.get()),path=FindAllPATH_Input.get())
  597. def Func_Args():#方法args统一转换(不支持Frame)
  598. global Var_Input, VarIndex_Input, Send_Input, UserPW_Input, SELE_Input, JS_Input, Time_Input
  599. try:
  600. time = int(Time_Input.get())
  601. except:
  602. time = 2
  603. try:
  604. index = int(VarIndex_Input.get())
  605. except:
  606. index = 0
  607. return dict(
  608. element_value = Var_Input.get(),
  609. index = index,
  610. text = Send_Input.get(),
  611. User = UserPW_Input.get(),
  612. Passwd = UserPW_Input.get(),
  613. deselect = SELE_Input.get(),
  614. JS = JS_Input.get(),
  615. time=time
  616. )
  617. def Page_Parser_addActionFunc3(func):
  618. global Page_Parser
  619. args = Func_Args3()
  620. FUNC = {'make_ActionChains':Page_Parser.make_ActionChains,'click':Page_Parser.ActionChains_click,
  621. 'double_click':Page_Parser.ActionChains_double_click,
  622. 'click_right':Page_Parser.ActionChains_click_right,'click_and_hold':Page_Parser.ActionChains_click_and_hold,
  623. 'release':Page_Parser.ActionChains_release,'drag_and_drop':Page_Parser.ActionChains_drag_and_drop,
  624. 'move':Page_Parser.ActionChains_move,'key_down':Page_Parser.ActionChains_key_down,
  625. 'key_up':Page_Parser.ActionChains_key_up,'send_keys_to_element':Page_Parser.ActionChains_send_keys_to_element,
  626. 'send_keys':Page_Parser.ActionChains_send_keys,'ActionChains_run':Page_Parser.ActionChains_run}.get(
  627. func,Page_Parser.make_ActionChains)
  628. FUNC(**args)
  629. Update_Parser_Func_BOX()
  630. def Page_Parser_addActionFunc2(func):
  631. global Page_Parser
  632. args = Func_Args2()
  633. FUNC = {'del_all_cookies':Page_Parser.del_all_cookies,'del_cookies':Page_Parser.del_cookies,'add_cookies':Page_Parser.add_cookies,
  634. 'update_cookies':Page_Parser.update_cookies,'get_cookies':Page_Parser.get_cookies,'get_all_cookies':Page_Parser.get_all_cookies,
  635. 'make_bs':Page_Parser.make_bs,'findAll':Page_Parser.findAll,'findAll_by_text':Page_Parser.findAll_by_text,
  636. 'get_children':Page_Parser.get_children,'get_offspring':Page_Parser.get_offspring,'get_up':Page_Parser.get_up,
  637. 'get_down':Page_Parser.get_down,'get_by_path':Page_Parser.get_by_path,'brothers':Page_Parser.get_brothers,
  638. 'png':Page_Parser.Webpage_snapshot,'to_json':Page_Parser.to_json}.get(func,Page_Parser.make_bs)
  639. FUNC(**args)
  640. Update_Parser_Func_BOX()
  641. def Page_Parser_addActionFunc(func):
  642. global Page_Parser
  643. args = Func_Args()
  644. FUNC = {'send_keys':Page_Parser.send_keys,'clear':Page_Parser.clear,'click':Page_Parser.click,'User_Passwd':Page_Parser.User_Passwd,
  645. 'accept':Page_Parser.accept,'dismiss':Page_Parser.dismiss,'submit':Page_Parser.submit,'deselect_by_index':Page_Parser.deselect_by_index,
  646. 'deselect_by_value':Page_Parser.deselect_by_value,'deselect_by_text':Page_Parser.deselect_by_text,'select_by_index':Page_Parser.select_by_index,
  647. 'select_by_value':Page_Parser.select_by_value,'select_by_text':Page_Parser.select_by_text,'back':Page_Parser.back,'forward':Page_Parser.forward,
  648. 'refresh':Page_Parser.refresh,'wait_sleep':Page_Parser.wait_sleep,'set_wait':Page_Parser.set_wait,'run_JS':Page_Parser.run_JS,
  649. 'out':Page_Parser.out_html,'get_Page':Page_Parser.to_text,'get_all_windows':Page_Parser.get_all_windows,
  650. 'get_now_windows':Page_Parser.get_now_windows,'switch_to_windwos':Page_Parser.switch_to_windwos
  651. }.get(func,Page_Parser.send_keys)
  652. FUNC(**args)
  653. Update_Parser_Func_BOX()
  654. def Page_Parser_addFrameFunc_FP(F=True):
  655. global Page_Parser, search_Input
  656. search = None if F else ''
  657. Page_Parser.find_switch_to_frame(search,True)
  658. Update_Parser_Func_BOX()
  659. def Page_Parser_addFrameFunc_id():
  660. global Page_Parser, search_Input
  661. search = search_Input.get()
  662. Page_Parser.find_switch_to_frame(search,True)
  663. Update_Parser_Func_BOX()
  664. def Page_Parser_addFindFunc(func):
  665. global search_all, search_Input,Page_Parser
  666. not_all = not(bool(search_all.get()))
  667. search = search_Input.get()
  668. FUNC = {'id':Page_Parser.find_ID,'name':Page_Parser.find_name,'class':Page_Parser.find_class,
  669. 'xpath':Page_Parser.find_xpath,'css':Page_Parser.find_css,'tag':Page_Parser.find_tag_name,
  670. 'link':Page_Parser.find_link_text,'partial_link':Page_Parser.find_partial_link_text,
  671. 'alert':Page_Parser.find_switch_to_alert,'active_element':Page_Parser.find_switch_to_active_element,
  672. 'frame':Page_Parser.find_switch_to_frame}.get(func,Page_Parser.find_ID)
  673. FUNC(search,not_all=not_all)
  674. Update_Parser_Func_BOX()
  675. def Del_Parser_Func():
  676. global Page_Parser
  677. try:
  678. index = Parser_Func_BOX.curselection()[0]
  679. Page_Parser.del_func(index,True)
  680. Update_Parser_Func_BOX()
  681. except:
  682. pass
  683. def Tra_Parser_Func():
  684. global Page_Parser
  685. try:
  686. Page_Parser.tra_func()
  687. Update_Parser_Func_BOX()
  688. except:
  689. pass
  690. def Update_Parser_Func_BOX():
  691. global Parser_Func_BOX,Page_Parser
  692. Parser_Func_BOX.delete(0,tkinter.END)
  693. Parser_Func_BOX.insert(tkinter.END, *Page_Parser.return_func(False)[::-1])
  694. def Update_cookies():
  695. global cookies_BOX,cookies_list,cookies_Input
  696. cookies = eval(cookies_Input.get(),{})
  697. if cookies_fixed.get() == '0':return False
  698. try:
  699. name = cookies_list[cookies_BOX.curselection()[0]].get('name')
  700. loader.update_cookies(name,cookies)
  701. cookies_fixed.set('0')
  702. except:
  703. pass
  704. def Add_cookies():
  705. global cookies_BOX,cookies_list,cookies_Input
  706. cookies = eval(cookies_Input.get(),{})
  707. if cookies_fixed.get() == '0':return False
  708. try:
  709. loader.Add_cookies(cookies)
  710. cookies_fixed.set('0')
  711. except:
  712. raise
  713. def Tra_cookies():
  714. global cookies_BOX,cookies_list
  715. if cookies_fixed.get() == '0':return False
  716. try:
  717. loader.Tra_cookies()
  718. cookies_fixed.set('0')
  719. except:
  720. pass
  721. def Del_cookies():
  722. global cookies_BOX,cookies_list
  723. if cookies_fixed.get() == '0':return False
  724. try:
  725. name = cookies_list[cookies_BOX.curselection()[0]].get('name')
  726. print(name)
  727. loader.Del_cookies(name)
  728. cookies_fixed.set('0')
  729. except:
  730. pass
  731. def cookies_BOX_Update(cookies):
  732. global cookies_BOX,cookies_list
  733. if cookies_fixed.get() == '0':
  734. cookies_list = cookies
  735. cookies_BOX.delete(0,tkinter.END)
  736. cookies_BOX.insert(0,*cookies)
  737. def Crawler_Stop():
  738. global startLoader_Stop
  739. startLoader_Stop = False
  740. loader.stop()
  741. def Crawler_Run():
  742. global startLoader_Stop
  743. def startLoader():
  744. global loader,Page_Parser,url,startLoader_Stop
  745. loader.stop()#把之前的停止
  746. while startLoader_Stop:
  747. if url.finish():break
  748. loader.strat_urlGet(func_cookie=cookies_BOX_Update)
  749. update_URLBOX()
  750. Page_Parser.Element_interaction(update_Status)
  751. loader.stop()
  752. startLoader_Stop = True
  753. new = threading.Thread(target=startLoader)
  754. new.start()
  755. update_URLBOX()
  756. def startDownloader():
  757. def startLoader():
  758. global loader,Page_Parser
  759. loader.strat_urlGet(func_cookie=cookies_BOX_Update)
  760. update_URLBOX()
  761. Page_Parser.Element_interaction(update_Status)
  762. loader.stop()
  763. new = threading.Thread(target=startLoader)
  764. new.start()
  765. def add_filter_func_HTTPS():
  766. global url
  767. url.Add_func(lambda url:re.match(re.compile('^https://'),url),'HTTPS过滤')
  768. update_Func_BOX()
  769. def add_filter_func_WWW():
  770. global url
  771. url.Add_func(lambda url:re.match(re.compile('.*www\.'),url),'www过滤')
  772. update_Func_BOX()
  773. def del_func():
  774. global URL_BOX
  775. index = Func_BOX.curselection()[0]
  776. url.Del_func(index)
  777. update_Func_BOX()
  778. def update_Func_BOX():
  779. global url,Func_BOX
  780. Func_BOX.delete(0,tkinter.END)
  781. Func_BOX.insert(tkinter.END,*url.return_func())
  782. def del_url():
  783. global URL_BOX
  784. index = URL_BOX.curselection()[0]
  785. url.del_url(index)
  786. update_URLBOX()
  787. def add_args():
  788. global URL_ARGS, UA_Input, use_Cookies_Input,FUNC_Input,DATA_Input,TimeOut_Input
  789. try:
  790. data = eval(DATA_Input.get(),{})
  791. except:
  792. data = {}
  793. try:
  794. TimeOut = int(TimeOut_Input.get())
  795. except:
  796. TimeOut = 5
  797. re = dict(
  798. func = FUNC_Input.get(),
  799. UA = UA_Input.get(),
  800. cookies = use_Cookies_Input.get(),
  801. data=data,
  802. time_out=TimeOut
  803. )
  804. name = ['no_js','no_java','no_plugins','first_run','head','no_img','new']
  805. for i in range(len(name)):
  806. re[name[i]] = bool(URL_ARGS[i].get())
  807. return re
  808. def add_url():
  809. global URL_Input,url
  810. args = add_args()
  811. new_url = URL_Input.get()
  812. if new_url == '':return
  813. url.add_url(new_url,**args)
  814. update_URLBOX()
  815. def add_url_from_tag():
  816. global URLTAG_Input,Page_Parser,Var_Input
  817. try:
  818. index = eval(VarIndex_Input.get(),{})
  819. except:
  820. index = slice(None,None)
  821. Page_Parser.add_url(element_value=Var_Input.get(),index=index,url_name=URLTAG_Input.get(),update_func=update_URLBOX,
  822. url_args=add_args())
  823. Update_Parser_Func_BOX()
  824. def update_URLBOX():
  825. global url,URL_BOX
  826. URL_BOX.delete(0,tkinter.END)
  827. URL_BOX.insert(tkinter.END,*url.return_url())
  828. if __name__ == "__main__":
  829. Main()